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

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

Issue 8342049: Added Protector, hooked up DSE verification with error bubble. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moved histograms to protector folder Created 9 years, 1 month 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
« no previous file with comments | « no previous file | chrome/browser/protector/histograms.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/basictypes.h"
6 #include "base/compiler_specific.h"
7 #include "base/logging.h"
8 #include "chrome/browser/protector/protector.h"
9 #include "chrome/browser/protector/setting_change.h"
10 #include "chrome/browser/search_engines/template_url.h"
11 #include "chrome/browser/search_engines/template_url_service.h"
12 #include "chrome/browser/webdata/keyword_table.h"
13 #include "chrome/common/url_constants.h"
14 #include "googleurl/src/gurl.h"
15
16 namespace protector {
17
18 class DefaultSearchProviderChange : public SettingChange {
19 public:
20 DefaultSearchProviderChange(const TemplateURL* old_url,
21 const TemplateURL* new_url);
22
23 // SettingChange overrides:
24 virtual string16 GetOldSetting() const OVERRIDE;
25 virtual string16 GetNewSetting() const OVERRIDE;
26 virtual void Accept(Protector* protector) OVERRIDE;
27 virtual void Revert(Protector* protector) OVERRIDE;
28 virtual void DoDefault(Protector* protector) OVERRIDE;
29
30 private:
31 virtual ~DefaultSearchProviderChange();
32
33 // Sets the given default search provider to profile that |protector| is
34 // guarding.
35 void SetDefaultSearchProvider(Protector* protector, int64 id);
36
37 int64 old_id_;
38 int64 new_id_;
39 string16 old_name_;
40 string16 new_name_;
41
42 DISALLOW_COPY_AND_ASSIGN(DefaultSearchProviderChange);
43 };
44
45 DefaultSearchProviderChange::DefaultSearchProviderChange(
46 const TemplateURL* old_url,
47 const TemplateURL* new_url)
48 : SettingChange(kSearchEngineChanged),
49 old_id_(0),
50 new_id_(0) {
51 DCHECK(new_url);
52 new_id_ = new_url->id();
53 new_name_ = new_url->short_name();
54 if (old_url) {
55 old_id_ = old_url->id();
56 old_name_ = old_url->short_name();
57 }
58 }
59
60 DefaultSearchProviderChange::~DefaultSearchProviderChange() {
61 }
62
63 string16 DefaultSearchProviderChange::GetOldSetting() const {
64 return old_name_;
65 }
66
67 string16 DefaultSearchProviderChange::GetNewSetting() const {
68 return new_name_;
69 }
70
71 void DefaultSearchProviderChange::Accept(Protector* protector) {
72 SetDefaultSearchProvider(protector, new_id_);
73 // TODO(avayvod): Add histrogram.
74 }
75
76 void DefaultSearchProviderChange::Revert(Protector* protector) {
77 SetDefaultSearchProvider(protector, old_id_);
78 if (!old_id_) {
79 // Open settings page in case the original setting was lost.
80 protector->OpenTab(
81 GURL(std::string(chrome::kChromeUISettingsURL) +
82 chrome::kSearchEnginesSubPage));
83 }
84 // TODO(avayvod): Add histrogram.
85 }
86
87 void DefaultSearchProviderChange::DoDefault(Protector* protector) {
88 SetDefaultSearchProvider(protector, old_id_);
89 // TODO(avayvod): Add histrogram.
90 }
91
92 void DefaultSearchProviderChange::SetDefaultSearchProvider(
93 Protector* protector,
94 int64 id) {
95 DCHECK(protector);
96 TemplateURLService* url_service = protector->GetTemplateURLService();
97 if (!url_service) {
98 LOG(WARNING) << "Can't get TemplateURLService object.";
99 return;
100 }
101 const TemplateURL* url = NULL;
102 const TemplateURLService::TemplateURLVector& urls =
103 url_service->GetTemplateURLs();
104 for (size_t i = 0; i < urls.size(); ++i)
105 if (urls[i]->id() == id) {
106 url = urls[i];
107 break;
108 }
109 if (!url)
110 url = url_service->FindNewDefaultSearchProvider();
111 url_service->SetDefaultSearchProvider(url);
112 }
113
114 SettingChange* CreateDefaultSearchProviderChange(
115 const TemplateURL* actual,
116 const TemplateURL* backup) {
117 return new DefaultSearchProviderChange(backup, actual);
118 }
119
120 } // namespace protector
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/protector/histograms.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698