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

Side by Side Diff: components/search_engines/search_host_to_urls_map.cc

Issue 684493002: Don't persist and sync omnibox extension keywords. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: change style to c++11 Created 6 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/search_engines/search_host_to_urls_map.h" 5 #include "components/search_engines/search_host_to_urls_map.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "components/search_engines/template_url.h" 8 #include "components/search_engines/template_url.h"
9 9
10 SearchHostToURLsMap::SearchHostToURLsMap() 10 SearchHostToURLsMap::SearchHostToURLsMap()
11 : initialized_(false) { 11 : initialized_(false) {
12 } 12 }
13 13
14 SearchHostToURLsMap::~SearchHostToURLsMap() { 14 SearchHostToURLsMap::~SearchHostToURLsMap() {
15 } 15 }
16 16
17 void SearchHostToURLsMap::Init( 17 void SearchHostToURLsMap::Init(
18 const TemplateURLService::TemplateURLVector& template_urls, 18 const TemplateURLService::TemplateURLVector& template_urls,
19 const SearchTermsData& search_terms_data) { 19 const SearchTermsData& search_terms_data) {
20 DCHECK(!initialized_); 20 DCHECK(!initialized_);
21 initialized_ = true; // Set here so Add doesn't assert. 21 initialized_ = true; // Set here so Add doesn't assert.
22 Add(template_urls, search_terms_data); 22 Add(template_urls, search_terms_data);
23 } 23 }
24 24
25 void SearchHostToURLsMap::Add(TemplateURL* template_url, 25 void SearchHostToURLsMap::Add(TemplateURL* template_url,
26 const SearchTermsData& search_terms_data) { 26 const SearchTermsData& search_terms_data) {
27 DCHECK(initialized_); 27 DCHECK(initialized_);
28 DCHECK(template_url); 28 DCHECK(template_url);
29 DCHECK(template_url->GetType() != TemplateURL::OMNIBOX_API_EXTENSION);
Peter Kasting 2014/10/29 18:55:51 Nit: DCHECK_NE (2 places)
vasilii 2014/11/03 15:14:30 Done.
29 30
30 const GURL url(template_url->GenerateSearchURL(search_terms_data)); 31 const GURL url(template_url->GenerateSearchURL(search_terms_data));
31 if (!url.is_valid() || !url.has_host()) 32 if (!url.is_valid() || !url.has_host())
32 return; 33 return;
33 34
34 host_to_urls_map_[url.host()].insert(template_url); 35 host_to_urls_map_[url.host()].insert(template_url);
35 } 36 }
36 37
37 void SearchHostToURLsMap::Remove(TemplateURL* template_url) { 38 void SearchHostToURLsMap::Remove(TemplateURL* template_url) {
38 DCHECK(initialized_); 39 DCHECK(initialized_);
39 DCHECK(template_url); 40 DCHECK(template_url);
41 DCHECK(template_url->GetType() != TemplateURL::OMNIBOX_API_EXTENSION);
40 42
41 for (HostToURLsMap::iterator i = host_to_urls_map_.begin(); 43 for (HostToURLsMap::iterator i = host_to_urls_map_.begin();
42 i != host_to_urls_map_.end(); ++i) { 44 i != host_to_urls_map_.end(); ++i) {
43 TemplateURLSet::iterator url_set_iterator = i->second.find(template_url); 45 TemplateURLSet::iterator url_set_iterator = i->second.find(template_url);
44 if (url_set_iterator != i->second.end()) { 46 if (url_set_iterator != i->second.end()) {
45 i->second.erase(url_set_iterator); 47 i->second.erase(url_set_iterator);
46 if (i->second.empty()) 48 if (i->second.empty())
47 host_to_urls_map_.erase(i); 49 host_to_urls_map_.erase(i);
48 // A given TemplateURL only occurs once in the map. As soon as we find the 50 // A given TemplateURL only occurs once in the map. As soon as we find the
49 // entry, stop. 51 // entry, stop.
(...skipping 22 matching lines...) Expand all
72 return &urls_for_host->second; 74 return &urls_for_host->second;
73 } 75 }
74 76
75 void SearchHostToURLsMap::Add( 77 void SearchHostToURLsMap::Add(
76 const TemplateURLService::TemplateURLVector& template_urls, 78 const TemplateURLService::TemplateURLVector& template_urls,
77 const SearchTermsData& search_terms_data) { 79 const SearchTermsData& search_terms_data) {
78 for (TemplateURLService::TemplateURLVector::const_iterator i( 80 for (TemplateURLService::TemplateURLVector::const_iterator i(
79 template_urls.begin()); i != template_urls.end(); ++i) 81 template_urls.begin()); i != template_urls.end(); ++i)
80 Add(*i, search_terms_data); 82 Add(*i, search_terms_data);
81 } 83 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698