Chromium Code Reviews| Index: extensions/browser/api/runtime/runtime_api.cc |
| diff --git a/chrome/browser/extensions/api/runtime/runtime_api.cc b/extensions/browser/api/runtime/runtime_api.cc |
| similarity index 50% |
| rename from chrome/browser/extensions/api/runtime/runtime_api.cc |
| rename to extensions/browser/api/runtime/runtime_api.cc |
| index fbb35ed0d676627af9358e0aed455a08ffa6bc79..c785989f0322ebe803fb067365364e0db58324e9 100644 |
| --- a/chrome/browser/extensions/api/runtime/runtime_api.cc |
| +++ b/extensions/browser/api/runtime/runtime_api.cc |
| @@ -2,7 +2,7 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "chrome/browser/extensions/api/runtime/runtime_api.h" |
| +#include "extensions/browser/api/runtime/runtime_api.h" |
| #include <utility> |
| @@ -11,48 +11,36 @@ |
| #include "base/memory/scoped_ptr.h" |
| #include "base/metrics/histogram.h" |
| #include "base/values.h" |
| -#include "chrome/browser/browser_process.h" |
| +#include "base/version.h" |
| #include "chrome/browser/chrome_notification_types.h" |
| -#include "chrome/browser/extensions/extension_service.h" |
| -#include "chrome/browser/extensions/extension_warning_service.h" |
| -#include "chrome/browser/extensions/updater/extension_updater.h" |
| -#include "chrome/browser/omaha_query_params/omaha_query_params.h" |
| -#include "chrome/browser/profiles/profile.h" |
| -#include "chrome/browser/profiles/profile_manager.h" |
| -#include "chrome/browser/ui/browser_finder.h" |
| -#include "chrome/browser/ui/browser_navigator.h" |
| -#include "chrome/browser/ui/browser_window.h" |
| -#include "chrome/common/extensions/api/runtime.h" |
| +#include "content/public/browser/browser_context.h" |
| #include "content/public/browser/child_process_security_policy.h" |
| #include "content/public/browser/notification_service.h" |
| #include "content/public/browser/render_process_host.h" |
| #include "content/public/browser/render_view_host.h" |
| +#include "extensions/browser/api/runtime/runtime_api_delegate.h" |
| #include "extensions/browser/event_router.h" |
| #include "extensions/browser/extension_host.h" |
| +#include "extensions/browser/extension_prefs.h" |
| #include "extensions/browser/extension_registry.h" |
| #include "extensions/browser/extension_system.h" |
| #include "extensions/browser/extensions_browser_client.h" |
| #include "extensions/browser/lazy_background_task_queue.h" |
| #include "extensions/browser/process_manager.h" |
| +#include "extensions/common/api/runtime.h" |
| #include "extensions/common/error_utils.h" |
| #include "extensions/common/extension.h" |
| #include "extensions/common/manifest_handlers/background_info.h" |
| #include "url/gurl.h" |
| #include "webkit/browser/fileapi/isolated_context.h" |
| -#if defined(OS_CHROMEOS) |
| -#include "chrome/browser/chromeos/login/user_manager.h" |
| -#include "chromeos/dbus/dbus_thread_manager.h" |
| -#include "chromeos/dbus/power_manager_client.h" |
| -#endif |
| - |
| using content::BrowserContext; |
| -namespace GetPlatformInfo = extensions::api::runtime::GetPlatformInfo; |
| +namespace GetPlatformInfo = extensions::core_api::runtime::GetPlatformInfo; |
| namespace extensions { |
| -namespace runtime = api::runtime; |
| +namespace runtime = core_api::runtime; |
| namespace { |
| @@ -64,10 +52,7 @@ const char kInstallReasonUpdate[] = "update"; |
| const char kInstallReasonInstall[] = "install"; |
| const char kInstallPreviousVersion[] = "previousVersion"; |
| const char kInvalidUrlError[] = "Invalid URL."; |
| -const char kUpdatesDisabledError[] = "Autoupdate is not enabled."; |
| -const char kUpdateFound[] = "update_available"; |
| -const char kUpdateNotFound[] = "no_update"; |
| -const char kUpdateThrottled[] = "throttled"; |
| +const char kPlatformInfoUnavailable[] = "Platform information unavailable."; |
| // A preference key storing the url loaded when an extension is uninstalled. |
| const char kUninstallUrl[] = "uninstall_url"; |
| @@ -77,14 +62,6 @@ const char kUninstallUrl[] = "uninstall_url"; |
| // with the equivalent Pepper API. |
| const char kPackageDirectoryPath[] = "crxfs"; |
| -// If an extension reloads itself within this many miliseconds of reloading |
| -// itself, the reload is considered suspiciously fast. |
| -const int kFastReloadTime = 10000; |
| - |
| -// After this many suspiciously fast consecutive reloads, an extension will get |
| -// disabled. |
| -const int kFastReloadCount = 5; |
| - |
| void DispatchOnStartupEventImpl(BrowserContext* browser_context, |
| const std::string& extension_id, |
| bool first_call, |
| @@ -113,27 +90,27 @@ void DispatchOnStartupEventImpl(BrowserContext* browser_context, |
| extension_id); |
| if (extension && BackgroundInfo::HasPersistentBackgroundPage(extension) && |
| first_call && |
| - system->lazy_background_task_queue()-> |
| - ShouldEnqueueTask(browser_context, extension)) { |
| + system->lazy_background_task_queue()->ShouldEnqueueTask(browser_context, |
| + extension)) { |
| system->lazy_background_task_queue()->AddPendingTask( |
| - browser_context, extension_id, |
| - base::Bind(&DispatchOnStartupEventImpl, |
| - browser_context, extension_id, false)); |
| + browser_context, |
| + extension_id, |
| + base::Bind( |
| + &DispatchOnStartupEventImpl, browser_context, extension_id, false)); |
| return; |
| } |
| scoped_ptr<base::ListValue> event_args(new base::ListValue()); |
| - scoped_ptr<Event> event(new Event(runtime::OnStartup::kEventName, |
| - event_args.Pass())); |
| + scoped_ptr<Event> event( |
| + new Event(runtime::OnStartup::kEventName, event_args.Pass())); |
| system->event_router()->DispatchEventToExtension(extension_id, event.Pass()); |
| } |
| void SetUninstallURL(ExtensionPrefs* prefs, |
| const std::string& extension_id, |
| const std::string& url_string) { |
| - prefs->UpdateExtensionPref(extension_id, |
| - kUninstallUrl, |
| - new base::StringValue(url_string)); |
| + prefs->UpdateExtensionPref( |
| + extension_id, kUninstallUrl, new base::StringValue(url_string)); |
| } |
| #if defined(ENABLE_EXTENSIONS) |
| @@ -158,19 +135,23 @@ BrowserContextKeyedAPIFactory<RuntimeAPI>* RuntimeAPI::GetFactoryInstance() { |
| } |
| RuntimeAPI::RuntimeAPI(content::BrowserContext* context) |
| - : browser_context_(context), |
| - dispatch_chrome_updated_event_(false), |
| - registered_for_updates_(false) { |
| - registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, |
| + : browser_context_(context), dispatch_chrome_updated_event_(false) { |
| + registrar_.Add(this, |
| + chrome::NOTIFICATION_EXTENSIONS_READY, |
| content::Source<BrowserContext>(context)); |
| registrar_.Add(this, |
| chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, |
| content::Source<BrowserContext>(context)); |
| - registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED, |
| + registrar_.Add(this, |
| + chrome::NOTIFICATION_EXTENSION_INSTALLED, |
| content::Source<BrowserContext>(context)); |
| - registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, |
| + registrar_.Add(this, |
| + chrome::NOTIFICATION_EXTENSION_UNINSTALLED, |
| content::Source<BrowserContext>(context)); |
| + delegate_ = ExtensionsBrowserClient::Get()->CreateRuntimeAPIDelegate( |
| + browser_context_); |
| + |
| // Check if registered events are up-to-date. We can only do this once |
| // per browser context, since it updates internal state when called. |
| dispatch_chrome_updated_event_ = |
| @@ -178,10 +159,7 @@ RuntimeAPI::RuntimeAPI(content::BrowserContext* context) |
| } |
| RuntimeAPI::~RuntimeAPI() { |
| - if (registered_for_updates_) { |
| - ExtensionSystem::Get(browser_context_)-> |
| - extension_service()->RemoveUpdateObserver(this); |
| - } |
| + delegate_->RemoveUpdateObserver(this); |
| } |
| void RuntimeAPI::Observe(int type, |
| @@ -220,16 +198,14 @@ void RuntimeAPI::OnExtensionsReady() { |
| // We're done restarting Chrome after an update. |
| dispatch_chrome_updated_event_ = false; |
| - registered_for_updates_ = true; |
| - |
| - ExtensionSystem* extension_system = ExtensionSystem::Get(browser_context_); |
| - extension_system->extension_service()->AddUpdateObserver(this); |
| + delegate_->AddUpdateObserver(this); |
| // RuntimeAPI is redirected in incognito, so |browser_context_| is never |
| // incognito. We don't observe incognito ProcessManagers but that is OK |
| // because we don't send onStartup events to incognito browser contexts. |
| DCHECK(!browser_context_->IsOffTheRecord()); |
| // Some tests use partially constructed Profiles without a process manager. |
| + ExtensionSystem* extension_system = ExtensionSystem::Get(browser_context_); |
| if (extension_system->process_manager()) |
| extension_system->process_manager()->AddObserver(this); |
| } |
| @@ -254,13 +230,7 @@ void RuntimeAPI::OnExtensionInstalled(const Extension* extension) { |
| if (extension->is_ephemeral()) |
| return; |
| - // Get the previous version to check if this is an upgrade. |
| - ExtensionService* service = ExtensionSystem::Get( |
| - browser_context_)->extension_service(); |
| - const Extension* old = service->GetExtensionById(extension->id(), true); |
| - Version old_version; |
| - if (old) |
| - old_version = *old->version(); |
| + Version old_version = delegate_->GetPreviousExtensionVersion(extension); |
| // Dispatch the onInstalled event. |
| base::MessageLoop::current()->PostTask( |
| @@ -270,7 +240,6 @@ void RuntimeAPI::OnExtensionInstalled(const Extension* extension) { |
| extension->id(), |
| old_version, |
| false)); |
| - |
| } |
| void RuntimeAPI::OnExtensionUninstalled(const Extension* extension) { |
| @@ -279,8 +248,7 @@ void RuntimeAPI::OnExtensionUninstalled(const Extension* extension) { |
| if (extension->is_ephemeral()) |
| return; |
| - Profile* profile = Profile::FromBrowserContext(browser_context_); |
| - RuntimeEventRouter::OnExtensionUninstalled(profile, extension->id()); |
| + RuntimeEventRouter::OnExtensionUninstalled(browser_context_, extension->id()); |
| } |
| void RuntimeAPI::Shutdown() { |
| @@ -294,76 +262,46 @@ void RuntimeAPI::Shutdown() { |
| } |
| void RuntimeAPI::OnAppUpdateAvailable(const Extension* extension) { |
| - Profile* profile = Profile::FromBrowserContext(browser_context_); |
| RuntimeEventRouter::DispatchOnUpdateAvailableEvent( |
| - profile, extension->id(), extension->manifest()->value()); |
| + browser_context_, extension->id(), extension->manifest()->value()); |
| } |
| void RuntimeAPI::OnChromeUpdateAvailable() { |
| - Profile* profile = Profile::FromBrowserContext(browser_context_); |
| - RuntimeEventRouter::DispatchOnBrowserUpdateAvailableEvent(profile); |
| + RuntimeEventRouter::DispatchOnBrowserUpdateAvailableEvent(browser_context_); |
| } |
| void RuntimeAPI::OnBackgroundHostStartup(const Extension* extension) { |
| RuntimeEventRouter::DispatchOnStartupEvent(browser_context_, extension->id()); |
| } |
| -void RuntimeAPI::MaybeReloadExtension(const std::string& extension_id) { |
| - std::pair<base::TimeTicks, int>& reload_info = |
| - last_reload_time_[extension_id]; |
| - base::TimeTicks now = base::TimeTicks::Now(); |
| - if (reload_info.first.is_null() || |
| - (now - reload_info.first).InMilliseconds() > kFastReloadTime) { |
| - reload_info.second = 0; |
| - } else { |
| - reload_info.second++; |
| - } |
| - if (!reload_info.first.is_null()) { |
| - UMA_HISTOGRAM_LONG_TIMES("Extensions.RuntimeReloadTime", |
| - now - reload_info.first); |
| - } |
| - UMA_HISTOGRAM_COUNTS_100("Extensions.RuntimeReloadFastCount", |
| - reload_info.second); |
| - reload_info.first = now; |
| - |
| - ExtensionService* service = |
| - ExtensionSystem::Get(browser_context_)->extension_service(); |
| - if (reload_info.second >= kFastReloadCount) { |
| - // Unloading an extension clears all warnings, so first terminate the |
| - // extension, and then add the warning. Since this is called from an |
| - // extension function unloading the extension has to be done |
| - // asynchronously. Fortunately PostTask guarentees FIFO order so just |
| - // post both tasks. |
| - base::MessageLoop::current()->PostTask( |
| - FROM_HERE, |
| - base::Bind(&ExtensionService::TerminateExtension, |
| - service->AsWeakPtr(), |
| - extension_id)); |
| - ExtensionWarningSet warnings; |
| - warnings.insert( |
| - ExtensionWarning::CreateReloadTooFrequentWarning(extension_id)); |
| - base::MessageLoop::current()->PostTask( |
| - FROM_HERE, |
| - base::Bind(&ExtensionWarningService::NotifyWarningsOnUI, |
| - browser_context_, |
| - warnings)); |
| - } else { |
| - // We can't call ReloadExtension directly, since when this method finishes |
| - // it tries to decrease the reference count for the extension, which fails |
| - // if the extension has already been reloaded; so instead we post a task. |
| - base::MessageLoop::current()->PostTask( |
| - FROM_HERE, |
| - base::Bind(&ExtensionService::ReloadExtension, |
| - service->AsWeakPtr(), |
| - extension_id)); |
| - } |
| +void RuntimeAPI::ReloadExtension(const std::string& extension_id) { |
| + delegate_->ReloadExtension(extension_id); |
| +} |
| + |
| +void RuntimeAPI::CheckForUpdates( |
| + const std::string& extension_id, |
| + const RuntimeAPIDelegate::UpdateCheckCallback& callback) { |
| + delegate_->CheckForUpdates(extension_id, callback); |
| +} |
| + |
| +void RuntimeAPI::OpenURL(const GURL& update_url) { |
| + delegate_->OpenURL(update_url); |
| +} |
| + |
| +bool RuntimeAPI::GetPlatformInfo(GetPlatformInfo::Results::PlatformInfo* info) { |
| + return delegate_->GetPlatformInfo(info); |
| +} |
| + |
| +bool RuntimeAPI::RestartDevice(std::string* error_message) { |
| + return delegate_->RestartDevice(error_message); |
| } |
| /////////////////////////////////////////////////////////////////////////////// |
| // static |
| void RuntimeEventRouter::DispatchOnStartupEvent( |
| - content::BrowserContext* context, const std::string& extension_id) { |
| + content::BrowserContext* context, |
| + const std::string& extension_id) { |
| DispatchOnStartupEventImpl(context, extension_id, true, NULL); |
| } |
| @@ -391,55 +329,55 @@ void RuntimeEventRouter::DispatchOnInstalledEvent( |
| info->SetString(kInstallReason, kInstallReasonInstall); |
| } |
| DCHECK(system->event_router()); |
| - scoped_ptr<Event> event(new Event(runtime::OnInstalled::kEventName, |
| - event_args.Pass())); |
| + scoped_ptr<Event> event( |
| + new Event(runtime::OnInstalled::kEventName, event_args.Pass())); |
| system->event_router()->DispatchEventWithLazyListener(extension_id, |
| event.Pass()); |
| } |
| // static |
| void RuntimeEventRouter::DispatchOnUpdateAvailableEvent( |
| - Profile* profile, |
| + content::BrowserContext* context, |
| const std::string& extension_id, |
| const base::DictionaryValue* manifest) { |
| - ExtensionSystem* system = ExtensionSystem::Get(profile); |
| + ExtensionSystem* system = ExtensionSystem::Get(context); |
| if (!system) |
| return; |
| scoped_ptr<base::ListValue> args(new base::ListValue); |
| args->Append(manifest->DeepCopy()); |
| DCHECK(system->event_router()); |
| - scoped_ptr<Event> event(new Event(runtime::OnUpdateAvailable::kEventName, |
| - args.Pass())); |
| + scoped_ptr<Event> event( |
| + new Event(runtime::OnUpdateAvailable::kEventName, args.Pass())); |
| system->event_router()->DispatchEventToExtension(extension_id, event.Pass()); |
| } |
| // static |
| void RuntimeEventRouter::DispatchOnBrowserUpdateAvailableEvent( |
| - Profile* profile) { |
| - ExtensionSystem* system = ExtensionSystem::Get(profile); |
| + content::BrowserContext* context) { |
| + ExtensionSystem* system = ExtensionSystem::Get(context); |
| if (!system) |
| return; |
| scoped_ptr<base::ListValue> args(new base::ListValue); |
| DCHECK(system->event_router()); |
| - scoped_ptr<Event> event(new Event( |
| - runtime::OnBrowserUpdateAvailable::kEventName, args.Pass())); |
| + scoped_ptr<Event> event( |
| + new Event(runtime::OnBrowserUpdateAvailable::kEventName, args.Pass())); |
| system->event_router()->BroadcastEvent(event.Pass()); |
| } |
| // static |
| void RuntimeEventRouter::DispatchOnRestartRequiredEvent( |
| - Profile* profile, |
| + content::BrowserContext* context, |
| const std::string& app_id, |
| - api::runtime::OnRestartRequired::Reason reason) { |
| - ExtensionSystem* system = ExtensionSystem::Get(profile); |
| + core_api::runtime::OnRestartRequired::Reason reason) { |
| + ExtensionSystem* system = ExtensionSystem::Get(context); |
| if (!system) |
| return; |
| scoped_ptr<Event> event( |
| new Event(runtime::OnRestartRequired::kEventName, |
| - api::runtime::OnRestartRequired::Create(reason))); |
| + core_api::runtime::OnRestartRequired::Create(reason))); |
| DCHECK(system->event_router()); |
| system->event_router()->DispatchEventToExtension(app_id, event.Pass()); |
| @@ -447,214 +385,111 @@ void RuntimeEventRouter::DispatchOnRestartRequiredEvent( |
| // static |
| void RuntimeEventRouter::OnExtensionUninstalled( |
| - Profile* profile, |
| + content::BrowserContext* context, |
| const std::string& extension_id) { |
| #if defined(ENABLE_EXTENSIONS) |
| - GURL uninstall_url(GetUninstallURL(ExtensionPrefs::Get(profile), |
| - extension_id)); |
| + GURL uninstall_url( |
| + GetUninstallURL(ExtensionPrefs::Get(context), extension_id)); |
| if (uninstall_url.is_empty()) |
| return; |
| - Browser* browser = chrome::FindLastActiveWithProfile(profile, |
| - chrome::GetActiveDesktop()); |
| - if (!browser) |
| - browser = new Browser(Browser::CreateParams(profile, |
| - chrome::GetActiveDesktop())); |
| - |
| - chrome::NavigateParams params(browser, uninstall_url, |
| - content::PAGE_TRANSITION_CLIENT_REDIRECT); |
| - params.disposition = NEW_FOREGROUND_TAB; |
| - params.user_gesture = false; |
| - chrome::Navigate(¶ms); |
| + RuntimeAPI::GetFactoryInstance()->Get(context)->OpenURL(uninstall_url); |
| #endif // defined(ENABLE_EXTENSIONS) |
| } |
| -bool RuntimeGetBackgroundPageFunction::RunAsync() { |
| - ExtensionSystem* system = ExtensionSystem::Get(GetProfile()); |
| - ExtensionHost* host = system->process_manager()-> |
| - GetBackgroundHostForExtension(extension_id()); |
| - if (system->lazy_background_task_queue()->ShouldEnqueueTask(GetProfile(), |
| +ExtensionFunction::ResponseAction RuntimeGetBackgroundPageFunction::Run() { |
| + ExtensionSystem* system = ExtensionSystem::Get(browser_context()); |
| + ExtensionHost* host = |
| + system->process_manager()->GetBackgroundHostForExtension(extension_id()); |
| + if (system->lazy_background_task_queue()->ShouldEnqueueTask(browser_context(), |
| GetExtension())) { |
| system->lazy_background_task_queue()->AddPendingTask( |
| - GetProfile(), |
| + browser_context(), |
| extension_id(), |
| base::Bind(&RuntimeGetBackgroundPageFunction::OnPageLoaded, this)); |
| } else if (host) { |
| OnPageLoaded(host); |
| } else { |
| - error_ = kNoBackgroundPageError; |
| - return false; |
| + return RespondNow(Error(kNoBackgroundPageError)); |
|
not at google - send to devlin
2014/05/05 21:50:26
yay!
|
| } |
| - return true; |
| + return RespondLater(); |
| } |
| void RuntimeGetBackgroundPageFunction::OnPageLoaded(ExtensionHost* host) { |
| if (host) { |
| - SendResponse(true); |
| + Respond(NoArguments()); |
| } else { |
| - error_ = kPageLoadError; |
| - SendResponse(false); |
| + Respond(Error(kPageLoadError)); |
| } |
| } |
| -bool RuntimeSetUninstallURLFunction::RunSync() { |
| +ExtensionFunction::ResponseAction RuntimeSetUninstallURLFunction::Run() { |
| std::string url_string; |
| - EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &url_string)); |
| + EXTENSION_FUNCTION_VALIDATE_TYPESAFE(args_->GetString(0, &url_string)); |
| GURL url(url_string); |
| if (!url.is_valid()) { |
| - error_ = ErrorUtils::FormatErrorMessage(kInvalidUrlError, url_string); |
| - return false; |
| + return RespondNow( |
| + Error(ErrorUtils::FormatErrorMessage(kInvalidUrlError, url_string))); |
| } |
| - |
| SetUninstallURL( |
| - ExtensionPrefs::Get(GetProfile()), extension_id(), url_string); |
| - return true; |
| + ExtensionPrefs::Get(browser_context()), extension_id(), url_string); |
| + return RespondNow(NoArguments()); |
| } |
| -bool RuntimeReloadFunction::RunSync() { |
| - RuntimeAPI::GetFactoryInstance()->Get(GetProfile())->MaybeReloadExtension( |
| +ExtensionFunction::ResponseAction RuntimeReloadFunction::Run() { |
| + RuntimeAPI::GetFactoryInstance()->Get(browser_context())->ReloadExtension( |
| extension_id()); |
| - return true; |
| + return RespondNow(NoArguments()); |
| } |
| -RuntimeRequestUpdateCheckFunction::RuntimeRequestUpdateCheckFunction() { |
| - registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UPDATE_FOUND, |
| - content::NotificationService::AllSources()); |
| +ExtensionFunction::ResponseAction RuntimeRequestUpdateCheckFunction::Run() { |
| + RuntimeAPI::GetFactoryInstance()->Get(browser_context())->CheckForUpdates( |
| + extension_id(), |
| + base::Bind(&RuntimeRequestUpdateCheckFunction::CheckComplete, this)); |
| + return RespondLater(); |
| } |
| -bool RuntimeRequestUpdateCheckFunction::RunAsync() { |
| - ExtensionSystem* system = ExtensionSystem::Get(GetProfile()); |
| - ExtensionService* service = system->extension_service(); |
| - ExtensionUpdater* updater = service->updater(); |
| - if (!updater) { |
| - error_ = kUpdatesDisabledError; |
| - return false; |
| - } |
| - |
| - did_reply_ = false; |
| - if (!updater->CheckExtensionSoon(extension_id(), base::Bind( |
| - &RuntimeRequestUpdateCheckFunction::CheckComplete, this))) { |
| - did_reply_ = true; |
| - SetResult(new base::StringValue(kUpdateThrottled)); |
| - SendResponse(true); |
| - } |
| - return true; |
| -} |
| - |
| -void RuntimeRequestUpdateCheckFunction::CheckComplete() { |
| - if (did_reply_) |
| - return; |
| - |
| - did_reply_ = true; |
| - |
| - // Since no UPDATE_FOUND notification was seen, this generally would mean |
| - // that no update is found, but a previous update check might have already |
| - // queued up an update, so check for that here to make sure we return the |
| - // right value. |
| - ExtensionSystem* system = ExtensionSystem::Get(GetProfile()); |
| - ExtensionService* service = system->extension_service(); |
| - const Extension* update = service->GetPendingExtensionUpdate(extension_id()); |
| - if (update) { |
| - ReplyUpdateFound(update->VersionString()); |
| +void RuntimeRequestUpdateCheckFunction::CheckComplete( |
| + const RuntimeAPIDelegate::UpdateCheckResult& result) { |
| + if (result.success) { |
| + base::ListValue* results = new base::ListValue; |
| + results->AppendString(result.response); |
| + base::DictionaryValue* details = new base::DictionaryValue; |
| + results->Append(details); |
| + details->SetString("version", result.version); |
| + Respond(MultipleArguments(results)); |
| } else { |
| - SetResult(new base::StringValue(kUpdateNotFound)); |
| - } |
| - SendResponse(true); |
| -} |
| - |
| -void RuntimeRequestUpdateCheckFunction::Observe( |
| - int type, |
| - const content::NotificationSource& source, |
| - const content::NotificationDetails& details) { |
| - if (did_reply_) |
| - return; |
| - |
| - DCHECK(type == chrome::NOTIFICATION_EXTENSION_UPDATE_FOUND); |
| - typedef const std::pair<std::string, Version> UpdateDetails; |
| - const std::string& id = content::Details<UpdateDetails>(details)->first; |
| - const Version& version = content::Details<UpdateDetails>(details)->second; |
| - if (id == extension_id()) { |
| - ReplyUpdateFound(version.GetString()); |
| + Respond(SingleArgument(new base::StringValue(result.response))); |
| } |
| } |
| -void RuntimeRequestUpdateCheckFunction::ReplyUpdateFound( |
| - const std::string& version) { |
| - did_reply_ = true; |
| - results_.reset(new base::ListValue); |
| - results_->AppendString(kUpdateFound); |
| - base::DictionaryValue* details = new base::DictionaryValue; |
| - results_->Append(details); |
| - details->SetString("version", version); |
| - SendResponse(true); |
| -} |
| - |
| -bool RuntimeRestartFunction::RunSync() { |
| -#if defined(OS_CHROMEOS) |
| - if (chromeos::UserManager::Get()->IsLoggedInAsKioskApp()) { |
| - chromeos::DBusThreadManager::Get() |
| - ->GetPowerManagerClient() |
| - ->RequestRestart(); |
| - return true; |
| +ExtensionFunction::ResponseAction RuntimeRestartFunction::Run() { |
| + std::string message; |
| + bool result = |
| + RuntimeAPI::GetFactoryInstance()->Get(browser_context())->RestartDevice( |
| + &message); |
| + if (!result) { |
| + return RespondNow(Error(message)); |
| } |
| -#endif |
| - SetError("Function available only for ChromeOS kiosk mode."); |
| - return false; |
| + return RespondNow(NoArguments()); |
| } |
| -bool RuntimeGetPlatformInfoFunction::RunSync() { |
| +ExtensionFunction::ResponseAction RuntimeGetPlatformInfoFunction::Run() { |
| GetPlatformInfo::Results::PlatformInfo info; |
| - |
| - const char* os = chrome::OmahaQueryParams::GetOS(); |
| - if (strcmp(os, "mac") == 0) { |
| - info.os = GetPlatformInfo::Results::PlatformInfo::OS_MAC_; |
| - } else if (strcmp(os, "win") == 0) { |
| - info.os = GetPlatformInfo::Results::PlatformInfo::OS_WIN_; |
| - } else if (strcmp(os, "android") == 0) { |
| - info.os = GetPlatformInfo::Results::PlatformInfo::OS_ANDROID_; |
| - } else if (strcmp(os, "cros") == 0) { |
| - info.os = GetPlatformInfo::Results::PlatformInfo::OS_CROS_; |
| - } else if (strcmp(os, "linux") == 0) { |
| - info.os = GetPlatformInfo::Results::PlatformInfo::OS_LINUX_; |
| - } else if (strcmp(os, "openbsd") == 0) { |
| - info.os = GetPlatformInfo::Results::PlatformInfo::OS_OPENBSD_; |
| - } else { |
| - NOTREACHED(); |
| - return false; |
| + if (!RuntimeAPI::GetFactoryInstance() |
| + ->Get(browser_context()) |
| + ->GetPlatformInfo(&info)) { |
| + return RespondNow(Error(kPlatformInfoUnavailable)); |
| } |
| - |
| - const char* arch = chrome::OmahaQueryParams::GetArch(); |
| - if (strcmp(arch, "arm") == 0) { |
| - info.arch = GetPlatformInfo::Results::PlatformInfo::ARCH_ARM; |
| - } else if (strcmp(arch, "x86") == 0) { |
| - info.arch = GetPlatformInfo::Results::PlatformInfo::ARCH_X86_32; |
| - } else if (strcmp(arch, "x64") == 0) { |
| - info.arch = GetPlatformInfo::Results::PlatformInfo::ARCH_X86_64; |
| - } else { |
| - NOTREACHED(); |
| - return false; |
| - } |
| - |
| - const char* nacl_arch = chrome::OmahaQueryParams::GetNaclArch(); |
| - if (strcmp(nacl_arch, "arm") == 0) { |
| - info.nacl_arch = GetPlatformInfo::Results::PlatformInfo::NACL_ARCH_ARM; |
| - } else if (strcmp(nacl_arch, "x86-32") == 0) { |
| - info.nacl_arch = GetPlatformInfo::Results::PlatformInfo::NACL_ARCH_X86_32; |
| - } else if (strcmp(nacl_arch, "x86-64") == 0) { |
| - info.nacl_arch = GetPlatformInfo::Results::PlatformInfo::NACL_ARCH_X86_64; |
| - } else { |
| - NOTREACHED(); |
| - return false; |
| - } |
| - |
| - results_ = GetPlatformInfo::Results::Create(info); |
| - return true; |
| + return RespondNow( |
| + MultipleArguments(GetPlatformInfo::Results::Create(info).release())); |
| } |
| -bool RuntimeGetPackageDirectoryEntryFunction::RunSync() { |
| +ExtensionFunction::ResponseAction |
| +RuntimeGetPackageDirectoryEntryFunction::Run() { |
| fileapi::IsolatedContext* isolated_context = |
| fileapi::IsolatedContext::GetInstance(); |
| DCHECK(isolated_context); |
| @@ -669,10 +504,9 @@ bool RuntimeGetPackageDirectoryEntryFunction::RunSync() { |
| content::ChildProcessSecurityPolicy::GetInstance(); |
| policy->GrantReadFileSystem(renderer_id, filesystem_id); |
| base::DictionaryValue* dict = new base::DictionaryValue(); |
| - SetResult(dict); |
| dict->SetString("fileSystemId", filesystem_id); |
| dict->SetString("baseName", relative_path); |
| - return true; |
| + return RespondNow(SingleArgument(dict)); |
| } |
| -} // namespace extensions |
| +} // namespace extensions |