Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/api/runtime/runtime_api.h" | 5 #include "chrome/browser/extensions/api/runtime/runtime_api.h" |
| 6 | 6 |
| 7 #include <utility> | |
| 8 | |
| 9 #include "base/logging.h" | |
| 7 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/values.h" | |
| 8 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/extensions/event_router.h" | 13 #include "chrome/browser/extensions/event_router.h" |
| 10 #include "chrome/browser/extensions/extension_host.h" | 14 #include "chrome/browser/extensions/extension_host.h" |
| 11 #include "chrome/browser/extensions/extension_process_manager.h" | 15 #include "chrome/browser/extensions/extension_process_manager.h" |
| 12 #include "chrome/browser/extensions/extension_service.h" | 16 #include "chrome/browser/extensions/extension_service.h" |
| 13 #include "chrome/browser/extensions/extension_system.h" | 17 #include "chrome/browser/extensions/extension_system.h" |
| 14 #include "chrome/browser/extensions/lazy_background_task_queue.h" | 18 #include "chrome/browser/extensions/lazy_background_task_queue.h" |
| 15 #include "chrome/browser/extensions/updater/extension_updater.h" | 19 #include "chrome/browser/extensions/updater/extension_updater.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/profiles/profile_manager.h" | 21 #include "chrome/browser/profiles/profile_manager.h" |
| 18 #include "chrome/browser/ui/browser_finder.h" | 22 #include "chrome/browser/ui/browser_finder.h" |
| 19 #include "chrome/browser/ui/browser_navigator.h" | 23 #include "chrome/browser/ui/browser_navigator.h" |
| 20 #include "chrome/browser/ui/browser_window.h" | 24 #include "chrome/browser/ui/browser_window.h" |
| 21 #include "chrome/common/extensions/api/runtime.h" | 25 #include "chrome/common/extensions/api/runtime.h" |
| 22 #include "chrome/common/extensions/background_info.h" | 26 #include "chrome/common/extensions/background_info.h" |
| 23 #include "chrome/common/extensions/extension.h" | 27 #include "chrome/common/extensions/extension.h" |
| 24 #include "chrome/common/omaha_query_params/omaha_query_params.h" | 28 #include "chrome/common/omaha_query_params/omaha_query_params.h" |
| 25 #include "extensions/common/error_utils.h" | 29 #include "extensions/common/error_utils.h" |
| 26 #include "googleurl/src/gurl.h" | 30 #include "googleurl/src/gurl.h" |
| 27 | 31 |
| 28 namespace GetPlatformInfo = extensions::api::runtime::GetPlatformInfo; | 32 namespace GetPlatformInfo = extensions::api::runtime::GetPlatformInfo; |
| 29 | 33 |
| 30 namespace extensions { | 34 namespace extensions { |
| 31 | 35 |
| 32 namespace { | 36 namespace { |
| 33 | 37 |
| 34 const char kOnStartupEvent[] = "runtime.onStartup"; | 38 const char kOnStartupEvent[] = "runtime.onStartup"; |
| 35 const char kOnInstalledEvent[] = "runtime.onInstalled"; | 39 const char kOnInstalledEvent[] = "runtime.onInstalled"; |
| 36 const char kOnUpdateAvailableEvent[] = "runtime.onUpdateAvailable"; | 40 const char kOnUpdateAvailableEvent[] = "runtime.onUpdateAvailable"; |
| 37 const char kOnBrowserUpdateAvailableEvent[] = | 41 const char kOnRestartRequiredEvent[] = "runtime.onRestartRequired"; |
| 38 "runtime.onBrowserUpdateAvailable"; | |
| 39 const char kNoBackgroundPageError[] = "You do not have a background page."; | 42 const char kNoBackgroundPageError[] = "You do not have a background page."; |
| 40 const char kPageLoadError[] = "Background page failed to load."; | 43 const char kPageLoadError[] = "Background page failed to load."; |
| 41 const char kInstallReason[] = "reason"; | 44 const char kInstallReason[] = "reason"; |
| 42 const char kInstallReasonChromeUpdate[] = "chrome_update"; | 45 const char kInstallReasonChromeUpdate[] = "chrome_update"; |
| 43 const char kInstallReasonUpdate[] = "update"; | 46 const char kInstallReasonUpdate[] = "update"; |
| 44 const char kInstallReasonInstall[] = "install"; | 47 const char kInstallReasonInstall[] = "install"; |
| 45 const char kInstallPreviousVersion[] = "previousVersion"; | 48 const char kInstallPreviousVersion[] = "previousVersion"; |
| 46 const char kInvalidUrlError[] = "Invalid URL."; | 49 const char kInvalidUrlError[] = "Invalid URL."; |
| 50 const char kRestartReason[] = "reason"; | |
|
bartfab (slow)
2013/06/21 06:27:58
Where is this one used?
xiyuan
2013/06/21 16:50:56
Not used and removed.
| |
| 51 const char kRestartReasonAppUpdate[] = "app_update"; | |
| 52 const char kRestartReasonOsUpdate[] = "os_update"; | |
| 53 const char kRestartReasonPeriodic[] = "periodic"; | |
| 47 const char kUpdatesDisabledError[] = "Autoupdate is not enabled."; | 54 const char kUpdatesDisabledError[] = "Autoupdate is not enabled."; |
| 48 const char kUpdateFound[] = "update_available"; | 55 const char kUpdateFound[] = "update_available"; |
| 49 const char kUpdateNotFound[] = "no_update"; | 56 const char kUpdateNotFound[] = "no_update"; |
| 50 const char kUpdateThrottled[] = "throttled"; | 57 const char kUpdateThrottled[] = "throttled"; |
| 51 | 58 |
| 52 // A preference key storing the url loaded when an extension is uninstalled. | 59 // A preference key storing the url loaded when an extension is uninstalled. |
| 53 const char kUninstallUrl[] = "uninstall_url"; | 60 const char kUninstallUrl[] = "uninstall_url"; |
| 54 | 61 |
| 55 static void DispatchOnStartupEventImpl( | 62 static void DispatchOnStartupEventImpl( |
| 56 Profile* profile, | 63 Profile* profile, |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 return; | 168 return; |
| 162 | 169 |
| 163 scoped_ptr<ListValue> args(new ListValue); | 170 scoped_ptr<ListValue> args(new ListValue); |
| 164 args->Append(manifest->DeepCopy()); | 171 args->Append(manifest->DeepCopy()); |
| 165 DCHECK(system->event_router()); | 172 DCHECK(system->event_router()); |
| 166 scoped_ptr<Event> event(new Event(kOnUpdateAvailableEvent, args.Pass())); | 173 scoped_ptr<Event> event(new Event(kOnUpdateAvailableEvent, args.Pass())); |
| 167 system->event_router()->DispatchEventToExtension(extension_id, event.Pass()); | 174 system->event_router()->DispatchEventToExtension(extension_id, event.Pass()); |
| 168 } | 175 } |
| 169 | 176 |
| 170 // static | 177 // static |
| 171 void RuntimeEventRouter::DispatchOnBrowserUpdateAvailableEvent( | 178 void RuntimeEventRouter::DispatchOnRestartRequiredEvent( |
| 172 Profile* profile) { | 179 Profile* profile, |
| 180 const std::string& app_id, | |
| 181 RestartReason reason) { | |
| 173 ExtensionSystem* system = ExtensionSystem::Get(profile); | 182 ExtensionSystem* system = ExtensionSystem::Get(profile); |
| 174 if (!system) | 183 if (!system) |
| 175 return; | 184 return; |
| 176 | 185 |
| 177 scoped_ptr<ListValue> args(new ListValue); | 186 scoped_ptr<ListValue> args(new ListValue); |
| 187 switch (reason) { | |
| 188 case RESTART_REASON_APP_UPDATE: | |
| 189 args->AppendString(kRestartReasonAppUpdate); | |
| 190 break; | |
| 191 case RESTART_REASON_OS_UPDATE: | |
| 192 args->AppendString(kRestartReasonOsUpdate); | |
| 193 break; | |
| 194 case RESTART_REASON_PERIODIC: | |
| 195 args->AppendString(kRestartReasonPeriodic); | |
| 196 break; | |
| 197 default: | |
| 198 NOTREACHED() << "Unknown reboot reason=" << reason; | |
| 199 return; | |
| 200 } | |
| 201 | |
| 178 DCHECK(system->event_router()); | 202 DCHECK(system->event_router()); |
| 179 scoped_ptr<Event> event(new Event(kOnBrowserUpdateAvailableEvent, | 203 scoped_ptr<Event> event(new Event(kOnRestartRequiredEvent, args.Pass())); |
| 180 args.Pass())); | 204 system->event_router()->DispatchEventToExtension(app_id, event.Pass()); |
| 181 system->event_router()->BroadcastEvent(event.Pass()); | |
| 182 } | 205 } |
| 183 | 206 |
| 184 // static | 207 // static |
| 185 void RuntimeEventRouter::OnExtensionUninstalled( | 208 void RuntimeEventRouter::OnExtensionUninstalled( |
| 186 Profile *profile, | 209 Profile* profile, |
| 187 const std::string& extension_id) { | 210 const std::string& extension_id) { |
| 188 #if defined(ENABLE_EXTENSIONS) | 211 #if defined(ENABLE_EXTENSIONS) |
| 189 GURL uninstall_url(GetUninstallUrl(ExtensionPrefs::Get(profile), | 212 GURL uninstall_url(GetUninstallUrl(ExtensionPrefs::Get(profile), |
| 190 extension_id)); | 213 extension_id)); |
| 191 | 214 |
| 192 if (uninstall_url.is_empty()) | 215 if (uninstall_url.is_empty()) |
| 193 return; | 216 return; |
| 194 | 217 |
| 195 Browser* browser = chrome::FindLastActiveWithProfile(profile, | 218 Browser* browser = chrome::FindLastActiveWithProfile(profile, |
| 196 chrome::GetActiveDesktop()); | 219 chrome::GetActiveDesktop()); |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 374 } else { | 397 } else { |
| 375 NOTREACHED(); | 398 NOTREACHED(); |
| 376 return false; | 399 return false; |
| 377 } | 400 } |
| 378 | 401 |
| 379 results_ = GetPlatformInfo::Results::Create(info); | 402 results_ = GetPlatformInfo::Results::Create(info); |
| 380 return true; | 403 return true; |
| 381 } | 404 } |
| 382 | 405 |
| 383 } // namespace extensions | 406 } // namespace extensions |
| OLD | NEW |