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

Side by Side Diff: chrome/browser/chromeos/drive/drive_app_registry.cc

Issue 22297004: drive: Stop making multiple GetAppList() requests from DriveAppRegistry (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: simplify Created 7 years, 4 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/chromeos/drive/drive_app_registry.h" 5 #include "chrome/browser/chromeos/drive/drive_app_registry.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 is_primary_selector(is_primary_selector) { 88 is_primary_selector(is_primary_selector) {
89 } 89 }
90 90
91 DriveAppRegistry::DriveAppFileSelector::~DriveAppFileSelector() { 91 DriveAppRegistry::DriveAppFileSelector::~DriveAppFileSelector() {
92 } 92 }
93 93
94 // DriveAppRegistry implementation. 94 // DriveAppRegistry implementation.
95 95
96 DriveAppRegistry::DriveAppRegistry(JobScheduler* scheduler) 96 DriveAppRegistry::DriveAppRegistry(JobScheduler* scheduler)
97 : scheduler_(scheduler), 97 : scheduler_(scheduler),
98 is_updating_(false),
98 weak_ptr_factory_(this) { 99 weak_ptr_factory_(this) {
99 } 100 }
100 101
101 DriveAppRegistry::~DriveAppRegistry() { 102 DriveAppRegistry::~DriveAppRegistry() {
102 STLDeleteValues(&app_extension_map_); 103 STLDeleteValues(&app_extension_map_);
103 STLDeleteValues(&app_mimetypes_map_); 104 STLDeleteValues(&app_mimetypes_map_);
104 } 105 }
105 106
106 void DriveAppRegistry::GetAppsForFile( 107 void DriveAppRegistry::GetAppsForFile(
107 const base::FilePath& file_path, 108 const base::FilePath& file_path,
(...skipping 22 matching lines...) Expand all
130 if (inserted_app_ids.find(it->second->app_id) == inserted_app_ids.end()) { 131 if (inserted_app_ids.find(it->second->app_id) == inserted_app_ids.end()) {
131 inserted_app_ids.insert(it->second->app_id); 132 inserted_app_ids.insert(it->second->app_id);
132 apps->push_back(it->second); 133 apps->push_back(it->second);
133 } 134 }
134 } 135 }
135 } 136 }
136 137
137 void DriveAppRegistry::Update() { 138 void DriveAppRegistry::Update() {
138 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 139 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
139 140
141 if (is_updating_) // There is already an update in progress.
142 return;
143
144 is_updating_ = true;
145
140 scheduler_->GetAppList( 146 scheduler_->GetAppList(
141 base::Bind(&DriveAppRegistry::UpdateAfterGetAppList, 147 base::Bind(&DriveAppRegistry::UpdateAfterGetAppList,
142 weak_ptr_factory_.GetWeakPtr())); 148 weak_ptr_factory_.GetWeakPtr()));
143 } 149 }
144 150
145 void DriveAppRegistry::UpdateAfterGetAppList( 151 void DriveAppRegistry::UpdateAfterGetAppList(
146 google_apis::GDataErrorCode gdata_error, 152 google_apis::GDataErrorCode gdata_error,
147 scoped_ptr<google_apis::AppList> app_list) { 153 scoped_ptr<google_apis::AppList> app_list) {
148 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 154 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
149 155
156 DCHECK(is_updating_);
157 is_updating_ = false;
158
150 FileError error = GDataToFileError(gdata_error); 159 FileError error = GDataToFileError(gdata_error);
151 if (error != FILE_ERROR_OK) { 160 if (error != FILE_ERROR_OK) {
152 // Failed to fetch the data from the server. We can do nothing here. 161 // Failed to fetch the data from the server. We can do nothing here.
153 return; 162 return;
154 } 163 }
155 164
156 DCHECK(app_list); 165 DCHECK(app_list);
157 166
158 url_to_name_map_.clear(); 167 url_to_name_map_.clear();
159 STLDeleteValues(&app_extension_map_); 168 STLDeleteValues(&app_extension_map_);
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 web_app->app_icons, 275 web_app->app_icons,
267 web_app->document_icons, 276 web_app->document_icons,
268 web_store_id, 277 web_store_id,
269 UTF8ToUTF16(product_iter->second), // app name. 278 UTF8ToUTF16(product_iter->second), // app name.
270 web_app->object_type, 279 web_app->object_type,
271 web_app->is_primary_selector))); 280 web_app->is_primary_selector)));
272 } 281 }
273 } 282 }
274 283
275 } // namespace drive 284 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/drive_app_registry.h ('k') | chrome/browser/chromeos/drive/drive_app_registry_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698