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

Side by Side Diff: chrome/browser/sync/glue/extension_change_processor.cc

Issue 7327007: Moving notification types which are chrome specific to a new header file chrome_notification_type... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/sync/glue/extension_change_processor.h" 5 #include "chrome/browser/sync/glue/extension_change_processor.h"
6 6
7 #include <sstream> 7 #include <sstream>
8 #include <string> 8 #include <string>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "chrome/browser/extensions/extension_service.h" 11 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/browser/extensions/extension_sync_data.h" 12 #include "chrome/browser/extensions/extension_sync_data.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/sync/glue/extension_sync.h" 14 #include "chrome/browser/sync/glue/extension_sync.h"
15 #include "chrome/browser/sync/glue/extension_util.h" 15 #include "chrome/browser/sync/glue/extension_util.h"
16 #include "chrome/browser/sync/protocol/extension_specifics.pb.h" 16 #include "chrome/browser/sync/protocol/extension_specifics.pb.h"
17 #include "chrome/common/chrome_notification_types.h"
17 #include "chrome/common/extensions/extension.h" 18 #include "chrome/common/extensions/extension.h"
18 #include "content/browser/browser_thread.h" 19 #include "content/browser/browser_thread.h"
19 #include "content/common/notification_details.h" 20 #include "content/common/notification_details.h"
20 #include "content/common/notification_source.h" 21 #include "content/common/notification_source.h"
21 22
22 namespace browser_sync { 23 namespace browser_sync {
23 24
24 ExtensionChangeProcessor::ExtensionChangeProcessor( 25 ExtensionChangeProcessor::ExtensionChangeProcessor(
25 UnrecoverableErrorHandler* error_handler) 26 UnrecoverableErrorHandler* error_handler)
26 : ChangeProcessor(error_handler), 27 : ChangeProcessor(error_handler),
27 traits_(GetExtensionSyncTraits()), 28 traits_(GetExtensionSyncTraits()),
28 profile_(NULL), 29 profile_(NULL),
29 extension_service_(NULL) { 30 extension_service_(NULL) {
30 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 31 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
31 DCHECK(error_handler); 32 DCHECK(error_handler);
32 } 33 }
33 34
34 ExtensionChangeProcessor::~ExtensionChangeProcessor() { 35 ExtensionChangeProcessor::~ExtensionChangeProcessor() {
35 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
36 } 37 }
37 38
38 // TODO(akalin): We need to make sure events we receive from either 39 // TODO(akalin): We need to make sure events we receive from either
39 // the browser or the syncapi are done in order; this is tricky since 40 // the browser or the syncapi are done in order; this is tricky since
40 // some events (e.g., extension installation) are done asynchronously. 41 // some events (e.g., extension installation) are done asynchronously.
41 42
42 void ExtensionChangeProcessor::Observe(NotificationType type, 43 void ExtensionChangeProcessor::Observe(int type,
43 const NotificationSource& source, 44 const NotificationSource& source,
44 const NotificationDetails& details) { 45 const NotificationDetails& details) {
45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
46 DCHECK(running()); 47 DCHECK(running());
47 DCHECK(profile_); 48 DCHECK(profile_);
48 if ((type != NotificationType::EXTENSION_LOADED) && 49 if ((type != chrome::NOTIFICATION_EXTENSION_LOADED) &&
49 (type != NotificationType::EXTENSION_UPDATE_DISABLED) && 50 (type != chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED) &&
50 (type != NotificationType::EXTENSION_UNLOADED)) { 51 (type != chrome::NOTIFICATION_EXTENSION_UNLOADED)) {
51 LOG(DFATAL) << "Received unexpected notification of type " 52 LOG(DFATAL) << "Received unexpected notification of type "
52 << type.value; 53 << type;
53 return; 54 return;
54 } 55 }
55 56
56 // Filter out unhandled extensions first. 57 // Filter out unhandled extensions first.
57 DCHECK_EQ(Source<Profile>(source).ptr(), profile_); 58 DCHECK_EQ(Source<Profile>(source).ptr(), profile_);
58 const Extension& extension = 59 const Extension& extension =
59 (type == NotificationType::EXTENSION_UNLOADED) ? 60 (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) ?
60 *Details<UnloadedExtensionInfo>(details)->extension : 61 *Details<UnloadedExtensionInfo>(details)->extension :
61 *Details<const Extension>(details).ptr(); 62 *Details<const Extension>(details).ptr();
62 if (!traits_.is_valid_and_syncable(extension)) { 63 if (!traits_.is_valid_and_syncable(extension)) {
63 return; 64 return;
64 } 65 }
65 66
66 const std::string& id = extension.id(); 67 const std::string& id = extension.id();
67 68
68 // Then handle extension uninstalls. 69 // Then handle extension uninstalls.
69 if (type == NotificationType::EXTENSION_UNLOADED) { 70 if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) {
70 const UnloadedExtensionInfo& info = 71 const UnloadedExtensionInfo& info =
71 *Details<UnloadedExtensionInfo>(details).ptr(); 72 *Details<UnloadedExtensionInfo>(details).ptr();
72 if (info.reason == UnloadedExtensionInfo::UNINSTALL) { 73 if (info.reason == UnloadedExtensionInfo::UNINSTALL) {
73 VLOG(1) << "Removing server data for uninstalled extension " << id 74 VLOG(1) << "Removing server data for uninstalled extension " << id
74 << " of type " << info.extension->GetType(); 75 << " of type " << info.extension->GetType();
75 RemoveServerData(traits_, id, share_handle()); 76 RemoveServerData(traits_, id, share_handle());
76 return; 77 return;
77 } 78 }
78 } 79 }
79 80
80 VLOG(1) << "Updating server data for extension " << id 81 VLOG(1) << "Updating server data for extension " << id
81 << " (notification type = " << type.value << ")"; 82 << " (notification type = " << type << ")";
82 std::string error; 83 std::string error;
83 if (!UpdateServerData(traits_, extension, *extension_service_, 84 if (!UpdateServerData(traits_, extension, *extension_service_,
84 share_handle(), &error)) { 85 share_handle(), &error)) {
85 error_handler()->OnUnrecoverableError(FROM_HERE, error); 86 error_handler()->OnUnrecoverableError(FROM_HERE, error);
86 } 87 }
87 } 88 }
88 89
89 void ExtensionChangeProcessor::ApplyChangesFromSyncModel( 90 void ExtensionChangeProcessor::ApplyChangesFromSyncModel(
90 const sync_api::BaseTransaction* trans, 91 const sync_api::BaseTransaction* trans,
91 const sync_api::SyncManager::ChangeRecord* changes, 92 const sync_api::SyncManager::ChangeRecord* changes,
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 StopObserving(); 157 StopObserving();
157 profile_ = NULL; 158 profile_ = NULL;
158 extension_service_ = NULL; 159 extension_service_ = NULL;
159 } 160 }
160 161
161 void ExtensionChangeProcessor::StartObserving() { 162 void ExtensionChangeProcessor::StartObserving() {
162 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 163 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
163 DCHECK(profile_); 164 DCHECK(profile_);
164 165
165 notification_registrar_.Add( 166 notification_registrar_.Add(
166 this, NotificationType::EXTENSION_LOADED, 167 this, chrome::NOTIFICATION_EXTENSION_LOADED,
167 Source<Profile>(profile_)); 168 Source<Profile>(profile_));
168 // Despite the name, this notification is exactly like 169 // Despite the name, this notification is exactly like
169 // EXTENSION_LOADED but with an initial state of DISABLED. 170 // EXTENSION_LOADED but with an initial state of DISABLED.
170 notification_registrar_.Add( 171 notification_registrar_.Add(
171 this, NotificationType::EXTENSION_UPDATE_DISABLED, 172 this, chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED,
172 Source<Profile>(profile_)); 173 Source<Profile>(profile_));
173 174
174 notification_registrar_.Add( 175 notification_registrar_.Add(
175 this, NotificationType::EXTENSION_UNLOADED, 176 this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
176 Source<Profile>(profile_)); 177 Source<Profile>(profile_));
177 } 178 }
178 179
179 void ExtensionChangeProcessor::StopObserving() { 180 void ExtensionChangeProcessor::StopObserving() {
180 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 181 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
181 DCHECK(profile_); 182 DCHECK(profile_);
182 VLOG(1) << "Unobserving all notifications"; 183 VLOG(1) << "Unobserving all notifications";
183 notification_registrar_.RemoveAll(); 184 notification_registrar_.RemoveAll();
184 } 185 }
185 186
186 } // namespace browser_sync 187 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/extension_change_processor.h ('k') | chrome/browser/sync/glue/password_change_processor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698