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

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

Issue 7918001: [Sync] Move ChangeRecord into its own file (change_record.{h,cc}) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 9 years, 3 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/theme_change_processor.h" 5 #include "chrome/browser/sync/glue/theme_change_processor.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/tracked.h" 8 #include "base/tracked.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/sync/glue/theme_util.h" 10 #include "chrome/browser/sync/glue/theme_util.h"
11 #include "chrome/browser/sync/internal_api/change_record.h"
11 #include "chrome/browser/sync/internal_api/read_node.h" 12 #include "chrome/browser/sync/internal_api/read_node.h"
12 #include "chrome/browser/sync/internal_api/sync_manager.h"
13 #include "chrome/browser/sync/internal_api/write_node.h" 13 #include "chrome/browser/sync/internal_api/write_node.h"
14 #include "chrome/browser/sync/internal_api/write_transaction.h" 14 #include "chrome/browser/sync/internal_api/write_transaction.h"
15 #include "chrome/browser/sync/protocol/theme_specifics.pb.h" 15 #include "chrome/browser/sync/protocol/theme_specifics.pb.h"
16 #include "chrome/browser/sync/unrecoverable_error_handler.h" 16 #include "chrome/browser/sync/unrecoverable_error_handler.h"
17 #include "chrome/browser/themes/theme_service_factory.h" 17 #include "chrome/browser/themes/theme_service_factory.h"
18 #include "chrome/browser/themes/theme_service.h" 18 #include "chrome/browser/themes/theme_service.h"
19 #include "chrome/common/chrome_notification_types.h" 19 #include "chrome/common/chrome_notification_types.h"
20 #include "chrome/common/extensions/extension.h" 20 #include "chrome/common/extensions/extension.h"
21 #include "content/common/notification_details.h" 21 #include "content/common/notification_details.h"
22 #include "content/common/notification_source.h" 22 #include "content/common/notification_source.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 // Do a write only if something actually changed so as to guard 57 // Do a write only if something actually changed so as to guard
58 // against cycles. 58 // against cycles.
59 if (!AreThemeSpecificsEqual(old_theme_specifics, new_theme_specifics)) { 59 if (!AreThemeSpecificsEqual(old_theme_specifics, new_theme_specifics)) {
60 node.SetThemeSpecifics(new_theme_specifics); 60 node.SetThemeSpecifics(new_theme_specifics);
61 } 61 }
62 return; 62 return;
63 } 63 }
64 64
65 void ThemeChangeProcessor::ApplyChangesFromSyncModel( 65 void ThemeChangeProcessor::ApplyChangesFromSyncModel(
66 const sync_api::BaseTransaction* trans, 66 const sync_api::BaseTransaction* trans,
67 const sync_api::SyncManager::ChangeRecord* changes, 67 const sync_api::ImmutableChangeRecordList& changes) {
68 int change_count) {
69 if (!running()) { 68 if (!running()) {
70 return; 69 return;
71 } 70 }
72 // TODO(akalin): Normally, we should only have a single change and 71 // TODO(akalin): Normally, we should only have a single change and
73 // it should be an update. However, the syncapi may occasionally 72 // it should be an update. However, the syncapi may occasionally
74 // generates multiple changes. When we fix syncapi to not do that, 73 // generates multiple changes. When we fix syncapi to not do that,
75 // we can remove the extra logic below. See: 74 // we can remove the extra logic below. See:
76 // http://code.google.com/p/chromium/issues/detail?id=41696 . 75 // http://code.google.com/p/chromium/issues/detail?id=41696 .
77 if (change_count < 1) { 76 if (changes.Get().empty()) {
78 std::string err("Unexpected change_count: "); 77 error_handler()->OnUnrecoverableError(FROM_HERE,
79 err += change_count; 78 "Change list unexpectedly empty");
80 error_handler()->OnUnrecoverableError(FROM_HERE, err);
81 return; 79 return;
82 } 80 }
83 if (change_count > 1) { 81 const size_t change_count = changes.Get().size();
82 if (change_count > 1u) {
84 LOG(WARNING) << change_count << " theme changes detected; " 83 LOG(WARNING) << change_count << " theme changes detected; "
85 << "only applying the last one"; 84 << "only applying the last one";
86 } 85 }
87 const sync_api::SyncManager::ChangeRecord& change = 86 const sync_api::ChangeRecord& change =
88 changes[change_count - 1]; 87 changes.Get()[change_count - 1];
89 if (change.action != sync_api::SyncManager::ChangeRecord::ACTION_UPDATE && 88 if (change.action != sync_api::ChangeRecord::ACTION_UPDATE &&
90 change.action != sync_api::SyncManager::ChangeRecord::ACTION_DELETE) { 89 change.action != sync_api::ChangeRecord::ACTION_DELETE) {
91 std::string err = "strange theme change.action " + change.action; 90 std::string err = "strange theme change.action " + change.action;
92 error_handler()->OnUnrecoverableError(FROM_HERE, err); 91 error_handler()->OnUnrecoverableError(FROM_HERE, err);
93 return; 92 return;
94 } 93 }
95 sync_pb::ThemeSpecifics theme_specifics; 94 sync_pb::ThemeSpecifics theme_specifics;
96 // If the action is a delete, simply use the default values for 95 // If the action is a delete, simply use the default values for
97 // ThemeSpecifics, which would cause the default theme to be set. 96 // ThemeSpecifics, which would cause the default theme to be set.
98 if (change.action != sync_api::SyncManager::ChangeRecord::ACTION_DELETE) { 97 if (change.action != sync_api::ChangeRecord::ACTION_DELETE) {
99 sync_api::ReadNode node(trans); 98 sync_api::ReadNode node(trans);
100 if (!node.InitByIdLookup(change.id)) { 99 if (!node.InitByIdLookup(change.id)) {
101 error_handler()->OnUnrecoverableError(FROM_HERE, 100 error_handler()->OnUnrecoverableError(FROM_HERE,
102 "Theme node lookup failed."); 101 "Theme node lookup failed.");
103 return; 102 return;
104 } 103 }
105 DCHECK_EQ(node.GetModelType(), syncable::THEMES); 104 DCHECK_EQ(node.GetModelType(), syncable::THEMES);
106 DCHECK(profile_); 105 DCHECK(profile_);
107 theme_specifics = node.GetThemeSpecifics(); 106 theme_specifics = node.GetThemeSpecifics();
108 } 107 }
(...skipping 22 matching lines...) Expand all
131 ThemeServiceFactory::GetForProfile(profile_))); 130 ThemeServiceFactory::GetForProfile(profile_)));
132 } 131 }
133 132
134 void ThemeChangeProcessor::StopObserving() { 133 void ThemeChangeProcessor::StopObserving() {
135 DCHECK(profile_); 134 DCHECK(profile_);
136 VLOG(1) << "Unobserving all notifications"; 135 VLOG(1) << "Unobserving all notifications";
137 notification_registrar_.RemoveAll(); 136 notification_registrar_.RemoveAll();
138 } 137 }
139 138
140 } // namespace browser_sync 139 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/theme_change_processor.h ('k') | chrome/browser/sync/glue/typed_url_change_processor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698