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

Side by Side Diff: ios/chrome/browser/browser_state/browser_state_info_cache.cc

Issue 2420013005: Remove usage of FOR_EACH_OBSERVER macro in ios/ (Closed)
Patch Set: typo Created 4 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
« no previous file with comments | « no previous file | ios/chrome/browser/browsing_data/ios_chrome_browsing_data_remover.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "ios/chrome/browser/browser_state/browser_state_info_cache.h" 5 #include "ios/chrome/browser/browser_state/browser_state_info_cache.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 std::string key = CacheKeyFromBrowserStatePath(browser_state_path); 47 std::string key = CacheKeyFromBrowserStatePath(browser_state_path);
48 DictionaryPrefUpdate update(prefs_, prefs::kBrowserStateInfoCache); 48 DictionaryPrefUpdate update(prefs_, prefs::kBrowserStateInfoCache);
49 base::DictionaryValue* cache = update.Get(); 49 base::DictionaryValue* cache = update.Get();
50 50
51 std::unique_ptr<base::DictionaryValue> info(new base::DictionaryValue); 51 std::unique_ptr<base::DictionaryValue> info(new base::DictionaryValue);
52 info->SetString(kGAIAIdKey, gaia_id); 52 info->SetString(kGAIAIdKey, gaia_id);
53 info->SetString(kUserNameKey, user_name); 53 info->SetString(kUserNameKey, user_name);
54 cache->SetWithoutPathExpansion(key, info.release()); 54 cache->SetWithoutPathExpansion(key, info.release());
55 AddBrowserStateCacheKey(key); 55 AddBrowserStateCacheKey(key);
56 56
57 FOR_EACH_OBSERVER(BrowserStateInfoCacheObserver, observer_list_, 57 for (auto& observer : observer_list_)
58 OnBrowserStateAdded(browser_state_path)); 58 observer.OnBrowserStateAdded(browser_state_path);
59 } 59 }
60 60
61 void BrowserStateInfoCache::AddObserver( 61 void BrowserStateInfoCache::AddObserver(
62 BrowserStateInfoCacheObserver* observer) { 62 BrowserStateInfoCacheObserver* observer) {
63 observer_list_.AddObserver(observer); 63 observer_list_.AddObserver(observer);
64 } 64 }
65 65
66 void BrowserStateInfoCache::RemoveObserver( 66 void BrowserStateInfoCache::RemoveObserver(
67 BrowserStateInfoCacheObserver* observer) { 67 BrowserStateInfoCacheObserver* observer) {
68 observer_list_.RemoveObserver(observer); 68 observer_list_.RemoveObserver(observer);
69 } 69 }
70 70
71 void BrowserStateInfoCache::RemoveBrowserState( 71 void BrowserStateInfoCache::RemoveBrowserState(
72 const base::FilePath& browser_state_path) { 72 const base::FilePath& browser_state_path) {
73 size_t browser_state_index = 73 size_t browser_state_index =
74 GetIndexOfBrowserStateWithPath(browser_state_path); 74 GetIndexOfBrowserStateWithPath(browser_state_path);
75 if (browser_state_index == std::string::npos) { 75 if (browser_state_index == std::string::npos) {
76 NOTREACHED(); 76 NOTREACHED();
77 return; 77 return;
78 } 78 }
79 DictionaryPrefUpdate update(prefs_, prefs::kBrowserStateInfoCache); 79 DictionaryPrefUpdate update(prefs_, prefs::kBrowserStateInfoCache);
80 base::DictionaryValue* cache = update.Get(); 80 base::DictionaryValue* cache = update.Get();
81 std::string key = CacheKeyFromBrowserStatePath(browser_state_path); 81 std::string key = CacheKeyFromBrowserStatePath(browser_state_path);
82 cache->Remove(key, nullptr); 82 cache->Remove(key, nullptr);
83 sorted_keys_.erase(std::find(sorted_keys_.begin(), sorted_keys_.end(), key)); 83 sorted_keys_.erase(std::find(sorted_keys_.begin(), sorted_keys_.end(), key));
84 84
85 FOR_EACH_OBSERVER(BrowserStateInfoCacheObserver, observer_list_, 85 for (auto& observer : observer_list_)
86 OnBrowserStateWasRemoved(browser_state_path)); 86 observer.OnBrowserStateWasRemoved(browser_state_path);
87 } 87 }
88 88
89 size_t BrowserStateInfoCache::GetNumberOfBrowserStates() const { 89 size_t BrowserStateInfoCache::GetNumberOfBrowserStates() const {
90 return sorted_keys_.size(); 90 return sorted_keys_.size();
91 } 91 }
92 92
93 size_t BrowserStateInfoCache::GetIndexOfBrowserStateWithPath( 93 size_t BrowserStateInfoCache::GetIndexOfBrowserStateWithPath(
94 const base::FilePath& browser_state_path) const { 94 const base::FilePath& browser_state_path) const {
95 if (browser_state_path.DirName() != user_data_dir_) 95 if (browser_state_path.DirName() != user_data_dir_)
96 return std::string::npos; 96 return std::string::npos;
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 const base::FilePath& browser_state_path) const { 200 const base::FilePath& browser_state_path) const {
201 DCHECK(user_data_dir_ == browser_state_path.DirName()); 201 DCHECK(user_data_dir_ == browser_state_path.DirName());
202 base::FilePath base_name = browser_state_path.BaseName(); 202 base::FilePath base_name = browser_state_path.BaseName();
203 return base_name.MaybeAsASCII(); 203 return base_name.MaybeAsASCII();
204 } 204 }
205 205
206 void BrowserStateInfoCache::AddBrowserStateCacheKey(const std::string& key) { 206 void BrowserStateInfoCache::AddBrowserStateCacheKey(const std::string& key) {
207 sorted_keys_.insert( 207 sorted_keys_.insert(
208 std::upper_bound(sorted_keys_.begin(), sorted_keys_.end(), key), key); 208 std::upper_bound(sorted_keys_.begin(), sorted_keys_.end(), key), key);
209 } 209 }
OLDNEW
« no previous file with comments | « no previous file | ios/chrome/browser/browsing_data/ios_chrome_browsing_data_remover.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698