Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Side by Side Diff: chrome/browser/extensions/app_restore_service.cc

Issue 11829055: Create top level apps component and move some apps code there. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nits Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/extensions/app_restore_service.h"
6
7 #include "chrome/browser/extensions/api/app_runtime/app_runtime_api.h"
8 #include "chrome/browser/extensions/event_router.h"
9 #include "chrome/browser/extensions/extension_host.h"
10 #include "chrome/browser/extensions/extension_service.h"
11 #include "chrome/browser/extensions/extension_system.h"
12 #include "chrome/browser/prefs/pref_service.h"
13 #include "chrome/browser/prefs/scoped_user_pref_update.h"
14 #include "chrome/common/extensions/extension.h"
15 #include "chrome/common/extensions/extension_set.h"
16 #include "chrome/common/chrome_notification_types.h"
17 #include "chrome/common/pref_names.h"
18 #include "content/public/browser/notification_details.h"
19 #include "content/public/browser/notification_service.h"
20 #include "content/public/browser/notification_types.h"
21
22 namespace extensions {
23
24 AppRestoreService::AppRestoreService(Profile* profile)
25 : profile_(profile) {
26 registrar_.Add(
27 this, chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING,
28 content::NotificationService::AllSources());
29 registrar_.Add(
30 this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
31 content::NotificationService::AllSources());
32 registrar_.Add(
33 this, chrome::NOTIFICATION_APP_TERMINATING,
34 content::NotificationService::AllSources());
35 }
36
37 void AppRestoreService::HandleStartup(bool should_restore_apps) {
38 ExtensionService* extension_service =
39 ExtensionSystem::Get(profile_)->extension_service();
40 const ExtensionSet* extensions = extension_service->extensions();
41 ExtensionPrefs* extension_prefs = extension_service->extension_prefs();
42
43 for (ExtensionSet::const_iterator it = extensions->begin();
44 it != extensions->end(); ++it) {
45 const Extension* extension = *it;
46 if (extension_prefs->IsExtensionRunning(extension->id())) {
47 RecordAppStop(extension->id());
48 if (should_restore_apps)
49 RestoreApp(*it);
50 }
51 }
52 }
53
54 void AppRestoreService::Observe(int type,
55 const content::NotificationSource& source,
56 const content::NotificationDetails& details) {
57 switch (type) {
58 case chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: {
59 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr();
60 const Extension* extension = host->extension();
61 if (extension && extension->is_platform_app())
62 RecordAppStart(extension->id());
63 break;
64 }
65
66 case chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED: {
67 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr();
68 const Extension* extension = host->extension();
69 if (extension && extension->is_platform_app())
70 RecordAppStop(extension->id());
71 break;
72 }
73
74 case chrome::NOTIFICATION_APP_TERMINATING: {
75 // Stop listening to NOTIFICATION_EXTENSION_HOST_DESTROYED in particular
76 // as all extension hosts will be destroyed as a result of shutdown.
77 registrar_.RemoveAll();
78 break;
79 }
80 }
81 }
82
83
84 void AppRestoreService::RecordAppStart(const std::string& extension_id) {
85 ExtensionPrefs* extension_prefs =
86 ExtensionSystem::Get(profile_)->extension_service()->extension_prefs();
87 extension_prefs->SetExtensionRunning(extension_id, true);
88 }
89
90 void AppRestoreService::RecordAppStop(const std::string& extension_id) {
91 ExtensionPrefs* extension_prefs =
92 ExtensionSystem::Get(profile_)->extension_service()->extension_prefs();
93 extension_prefs->SetExtensionRunning(extension_id, false);
94 }
95
96 void AppRestoreService::RestoreApp(const Extension* extension) {
97 AppEventRouter::DispatchOnRestartedEvent(profile_, extension);
98 }
99
100 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/app_restore_service.h ('k') | chrome/browser/extensions/app_restore_service_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698