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

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 changes in separate files. Simplified objects ownership. Created 9 years, 2 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
« no previous file with comments | « no previous file | chrome/browser/protector/keys.h » ('j') | chrome/browser/protector/protector.cc » ('J')
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(
21 KeywordTable* table,
22 int64 old_id,
23 int64 new_id);
24
25 // SettingChange overrides:
26 virtual const string16& GetOldSetting() const OVERRIDE;
27 virtual const string16& GetNewSetting() const OVERRIDE;
28 virtual void Accept(Protector* protector) OVERRIDE;
29 virtual void Revert(Protector* protector) OVERRIDE;
30
31 private:
32 ~DefaultSearchProviderChange();
33
34 // ID of the new default search provider to be accepted.
35 int64 new_id_;
36
37 // Short name of the old default search provider.
38 string16 old_name_;
39
40 // Short name of the new default search provider.
41 string16 new_name_;
42
43 DISALLOW_COPY_AND_ASSIGN(DefaultSearchProviderChange);
44 };
45
46 DefaultSearchProviderChange::DefaultSearchProviderChange(
47 KeywordTable* table,
48 int64 old_id,
49 int64 new_id)
50 : SettingChange(kSearchEngineChanged),
51 new_id_(new_id),
52 old_name_(table->GetKeywordShortName(old_id)),
53 new_name_(table->GetKeywordShortName(new_id)) {
54 }
55
56 DefaultSearchProviderChange::~DefaultSearchProviderChange() {
57 }
58
59 const string16& DefaultSearchProviderChange::GetOldSetting() const {
60 return old_name_;
61 }
62
63 const string16& DefaultSearchProviderChange::GetNewSetting() const {
64 return new_name_;
65 }
66
67 void DefaultSearchProviderChange::Accept(Protector* protector) {
68 DCHECK(protector);
69 TemplateURLService* url_service = protector->GetTemplateURLService();
70 if (!url_service) {
71 LOG(WARNING) << "Can't get TemplateURLService object.";
72 return;
73 }
74 const TemplateURLService::TemplateURLVector& urls =
75 url_service->GetTemplateURLs();
76 for (size_t i = 0; i < urls.size(); ++i) {
77 if (urls[i]->id() == new_id_) {
78 url_service->SetDefaultSearchProvider(urls[i]);
79 return;
80 }
81 }
82 LOG(WARNING) << "Didn't find search provider with id " << new_id_;
83 // TODO(avayvod): Add histrogram.
84 }
85
86 void DefaultSearchProviderChange::Revert(Protector* protector) {
87 DCHECK(protector);
88 if (old_name_.empty()) {
89 TemplateURLService* url_service = protector->GetTemplateURLService();
90 if (url_service)
91 url_service->SetDefaultSearchProvider(NULL);
92 else
93 LOG(WARNING) << "Can't get TemplateURLService object.";
94 // Open settings page in case the original setting was lost.
95 protector->OpenTab(
96 GURL(std::string(chrome::kChromeUISettingsURL) +
97 chrome::kSearchEnginesSubPage));
98 }
99 // TODO(avayvod): Add histrogram.
100 }
101
102 SettingChange* CreateDefaultSearchProviderChange(
103 KeywordTable* table,
104 int64 old_id,
105 int64 new_id) {
106 return new DefaultSearchProviderChange(table, old_id, new_id);
107 }
108
109 } // namespace protector
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/protector/keys.h » ('j') | chrome/browser/protector/protector.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698