forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor download image-MIME-type-detection code.
Refactor duplicated image-MIME-type-detection code from DownloadCommands and DownloadItemNotification into a new DownloadItemModel::HasSupportedImageMimeType() method. BUG=605805 Review-Url: https://codereview.chromium.org/2219953004 Cr-Commit-Position: refs/heads/master@{#410382}
- Loading branch information
derat
authored and
Commit bot
committed
Aug 8, 2016
1 parent
eb1baaa
commit 759969d
Showing
11 changed files
with
173 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,4 @@ bool IsPaletteEnabled() { | |
switches::kAshEnablePalette); | ||
} | ||
|
||
} // namespace chromeos | ||
} // namespace ash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Copyright 2016 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/browser/chromeos/note_taking_app_utils.h" | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
#include "apps/launcher.h" | ||
#include "ash/common/system/chromeos/palette/palette_utils.h" | ||
#include "base/command_line.h" | ||
#include "base/files/file_path.h" | ||
#include "base/strings/string_split.h" | ||
#include "chrome/browser/profiles/profile.h" | ||
#include "chromeos/chromeos_switches.h" | ||
#include "extensions/browser/extension_registry.h" | ||
#include "extensions/common/extension.h" | ||
#include "url/gurl.h" | ||
|
||
namespace chromeos { | ||
namespace { | ||
|
||
// TODO(derat): Add more IDs. | ||
const char* const kExtensionIds[] = { | ||
"hmjkmjkepdijhoojdojkdfohbdgmmhki", // Google Keep app (Web Store) | ||
}; | ||
|
||
// Returns the first installed and enabled whitelisted note-taking app, or null | ||
// if none is installed. | ||
// TODO(derat): Instead of a using hardcoded list of IDs, use an app designated | ||
// by a pref. | ||
const extensions::Extension* GetApp(Profile* profile) { | ||
std::vector<std::string> ids; | ||
|
||
const std::string switch_value = | ||
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | ||
switches::kNoteTakingAppIds); | ||
if (!switch_value.empty()) { | ||
ids = base::SplitString(switch_value, ",", base::TRIM_WHITESPACE, | ||
base::SPLIT_WANT_NONEMPTY); | ||
} else { | ||
ids.assign(kExtensionIds, kExtensionIds + arraysize(kExtensionIds)); | ||
} | ||
|
||
const extensions::ExtensionRegistry* extension_registry = | ||
extensions::ExtensionRegistry::Get(profile); | ||
const extensions::ExtensionSet& enabled_extensions = | ||
extension_registry->enabled_extensions(); | ||
for (const auto& id : ids) { | ||
if (enabled_extensions.Contains(id)) { | ||
return extension_registry->GetExtensionById( | ||
id, extensions::ExtensionRegistry::ENABLED); | ||
} | ||
} | ||
return nullptr; | ||
} | ||
|
||
} // namespace | ||
|
||
bool IsNoteTakingAppAvailable(Profile* profile) { | ||
DCHECK(profile); | ||
return ash::IsPaletteEnabled() && GetApp(profile); | ||
} | ||
|
||
void LaunchNoteTakingAppForNewNote(Profile* profile, | ||
const base::FilePath& path) { | ||
DCHECK(profile); | ||
const extensions::Extension* app = GetApp(profile); | ||
if (!app) { | ||
LOG(ERROR) << "Failed to find note-taking app"; | ||
return; | ||
} | ||
|
||
// TODO: Launch with an "action" launch source and the appropriate action type | ||
// to create a new note once that's been added to chrome.appRuntime. | ||
if (path.empty()) | ||
apps::LaunchPlatformApp(profile, app, extensions::SOURCE_UNTRACKED); | ||
else | ||
apps::LaunchPlatformAppWithPath(profile, app, path); | ||
} | ||
|
||
} // namespace chromeos |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright 2016 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef CHROME_BROWSER_CHROMEOS_NOTE_TAKING_APP_UTILS_H_ | ||
#define CHROME_BROWSER_CHROMEOS_NOTE_TAKING_APP_UTILS_H_ | ||
|
||
class Profile; | ||
|
||
namespace base { | ||
class FilePath; | ||
} // namespace base | ||
|
||
namespace chromeos { | ||
|
||
// Returns true if an app that can be used to take notes is available. | ||
bool IsNoteTakingAppAvailable(Profile* profile); | ||
|
||
// Launches the note-taking app to create a new note, optionally additionally | ||
// passing a file (|path| may be empty). IsNoteTakingAppAvailable() must be | ||
// called first. | ||
void LaunchNoteTakingAppForNewNote(Profile* profile, | ||
const base::FilePath& path); | ||
|
||
} // namespace chromeos | ||
|
||
#endif // CHROME_BROWSER_CHROMEOS_NOTE_TAKING_APP_UTILS_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters