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

Side by Side Diff: chrome/browser/protector/protector_service.cc

Issue 10065016: [protector] Refactoring of --no-protector code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge Created 8 years, 8 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) 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/protector/protector_service.h" 5 #include "chrome/browser/protector/protector_service.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "chrome/browser/google/google_util.h" 8 #include "chrome/browser/google/google_util.h"
9 #include "chrome/browser/prefs/pref_service.h" 9 #include "chrome/browser/prefs/pref_service.h"
10 #include "chrome/browser/protector/composite_settings_change.h" 10 #include "chrome/browser/protector/composite_settings_change.h"
11 #include "chrome/browser/protector/keys.h" 11 #include "chrome/browser/protector/keys.h"
12 #include "chrome/browser/protector/protected_prefs_watcher.h" 12 #include "chrome/browser/protector/protected_prefs_watcher.h"
13 #include "chrome/browser/protector/protector_utils.h"
13 #include "chrome/browser/protector/settings_change_global_error.h" 14 #include "chrome/browser/protector/settings_change_global_error.h"
14 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
15 #include "chrome/common/chrome_notification_types.h" 16 #include "chrome/common/chrome_notification_types.h"
16 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
17 #include "content/public/browser/notification_source.h" 18 #include "content/public/browser/notification_source.h"
18 #include "net/base/registry_controlled_domain.h" 19 #include "net/base/registry_controlled_domain.h"
19 20
20 namespace protector { 21 namespace protector {
21 22
22 namespace { 23 namespace {
(...skipping 16 matching lines...) Expand all
39 // Start observing pref changes. 40 // Start observing pref changes.
40 prefs_watcher_.reset(new ProtectedPrefsWatcher(profile)); 41 prefs_watcher_.reset(new ProtectedPrefsWatcher(profile));
41 } 42 }
42 43
43 ProtectorService::~ProtectorService() { 44 ProtectorService::~ProtectorService() {
44 DCHECK(!IsShowingChange()); // Should have been dismissed by Shutdown. 45 DCHECK(!IsShowingChange()); // Should have been dismissed by Shutdown.
45 } 46 }
46 47
47 void ProtectorService::ShowChange(BaseSettingChange* change) { 48 void ProtectorService::ShowChange(BaseSettingChange* change) {
48 DCHECK(change); 49 DCHECK(change);
50 // Change instance will either be owned by |this| or deleted after this call.
51 scoped_ptr<BaseSettingChange> change_ptr(change);
49 52
50 DVLOG(1) << "Init change"; 53 DVLOG(1) << "Init change";
51 if (!change->Init(profile_)) { 54 if (!protector::IsEnabled()) {
55 change_ptr->InitWhenDisabled(profile_);
56 return;
57 } else if (!change_ptr->Init(profile_)) {
52 LOG(WARNING) << "Error while initializing, dismissing change"; 58 LOG(WARNING) << "Error while initializing, dismissing change";
53 delete change;
54 return; 59 return;
55 } 60 }
56 61
57 Item* item_to_merge_with = FindItemToMergeWith(change); 62 Item* item_to_merge_with = FindItemToMergeWith(change_ptr.get());
58 if (item_to_merge_with) { 63 if (item_to_merge_with) {
59 // CompositeSettingsChange takes ownership of merged changes. 64 // CompositeSettingsChange takes ownership of merged changes.
60 BaseSettingChange* existing_change = item_to_merge_with->change.release(); 65 BaseSettingChange* existing_change = item_to_merge_with->change.release();
61 CompositeSettingsChange* merged_change = existing_change->MergeWith(change); 66 CompositeSettingsChange* merged_change =
67 existing_change->MergeWith(change_ptr.release());
62 item_to_merge_with->change.reset(merged_change); 68 item_to_merge_with->change.reset(merged_change);
63 item_to_merge_with->was_merged = true; 69 item_to_merge_with->was_merged = true;
64 if (item_to_merge_with->error->GetBubbleView()) 70 if (item_to_merge_with->error->GetBubbleView())
65 item_to_merge_with->show_when_merged = true; 71 item_to_merge_with->show_when_merged = true;
66 // Remove old GlobalError instance. Later in OnRemovedFromProfile() a new 72 // Remove old GlobalError instance. Later in OnRemovedFromProfile() a new
67 // GlobalError instance will be created for the composite change. 73 // GlobalError instance will be created for the composite change.
68 item_to_merge_with->error->RemoveFromProfile(); 74 item_to_merge_with->error->RemoveFromProfile();
69 } else { 75 } else {
70 Item new_item; 76 Item new_item;
71 SettingsChangeGlobalError* error = 77 SettingsChangeGlobalError* error =
72 new SettingsChangeGlobalError(change, this); 78 new SettingsChangeGlobalError(change_ptr.get(), this);
73 new_item.error.reset(error); 79 new_item.error.reset(error);
74 new_item.change.reset(change); 80 new_item.change.reset(change_ptr.release());
75 items_.push_back(new_item); 81 items_.push_back(new_item);
76 // Do not show the bubble immediately if another one is active. 82 // Do not show the bubble immediately if another one is active.
77 error->AddToProfile(profile_, !has_active_change_); 83 error->AddToProfile(profile_, !has_active_change_);
78 has_active_change_ = true; 84 has_active_change_ = true;
79 } 85 }
80 } 86 }
81 87
82 bool ProtectorService::IsShowingChange() const { 88 bool ProtectorService::IsShowingChange() const {
83 return !items_.empty(); 89 return !items_.empty();
84 } 90 }
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 ProtectorService::MatchItemByError::MatchItemByError( 210 ProtectorService::MatchItemByError::MatchItemByError(
205 const SettingsChangeGlobalError* other) : other_(other) { 211 const SettingsChangeGlobalError* other) : other_(other) {
206 } 212 }
207 213
208 bool ProtectorService::MatchItemByError::operator()( 214 bool ProtectorService::MatchItemByError::operator()(
209 const ProtectorService::Item& item) { 215 const ProtectorService::Item& item) {
210 return other_ == item.error.get(); 216 return other_ == item.error.get();
211 } 217 }
212 218
213 } // namespace protector 219 } // namespace protector
OLDNEW
« no previous file with comments | « chrome/browser/protector/protected_prefs_watcher.cc ('k') | chrome/browser/search_engines/template_url_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698