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

Side by Side Diff: chrome/browser/ui/webui/chromeos/drive_internals_ui.cc

Issue 10825062: gdata: Add Cache Contents section to chrome:drive-internals (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 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
« no previous file with comments | « chrome/browser/resources/chromeos/drive_internals.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/ui/webui/chromeos/drive_internals_ui.h" 5 #include "chrome/browser/ui/webui/chromeos/drive_internals_ui.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/stringprintf.h" 10 #include "base/stringprintf.h"
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 file_specific_info.is_hosted_document()); 134 file_specific_info.is_hosted_document());
135 } 135 }
136 136
137 return out; 137 return out;
138 } 138 }
139 139
140 // Class to handle messages from chrome://drive-internals. 140 // Class to handle messages from chrome://drive-internals.
141 class DriveInternalsWebUIHandler : public content::WebUIMessageHandler { 141 class DriveInternalsWebUIHandler : public content::WebUIMessageHandler {
142 public: 142 public:
143 DriveInternalsWebUIHandler() 143 DriveInternalsWebUIHandler()
144 : weak_ptr_factory_(this) { 144 : num_pending_reads_(0),
145 weak_ptr_factory_(this) {
145 } 146 }
146 147
147 virtual ~DriveInternalsWebUIHandler() { 148 virtual ~DriveInternalsWebUIHandler() {
148 } 149 }
149 150
150 private: 151 private:
151 // WebUIMessageHandler override. 152 // WebUIMessageHandler override.
152 virtual void RegisterMessages() OVERRIDE; 153 virtual void RegisterMessages() OVERRIDE;
153 154
154 // Returns a GDataSystemService. 155 // Returns a GDataSystemService.
155 gdata::GDataSystemService* GetSystemService(); 156 gdata::GDataSystemService* GetSystemService();
156 157
157 // Called when the page is first loaded. 158 // Called when the page is first loaded.
158 void OnPageLoaded(const base::ListValue* args); 159 void OnPageLoaded(const base::ListValue* args);
159 160
160 // Called when GetGCacheContents() is complete. 161 // Called when GetGCacheContents() is complete.
161 void OnGetGCacheContents(base::ListValue* gcache_contents); 162 void OnGetGCacheContents(base::ListValue* gcache_contents);
162 163
163 // Called when ReadDirectoryByPath() is complete. 164 // Called when ReadDirectoryByPath() is complete.
164 void OnReadDirectoryByPath(const FilePath& parent_path, 165 void OnReadDirectoryByPath(const FilePath& parent_path,
165 gdata::GDataFileError error, 166 gdata::GDataFileError error,
166 bool hide_hosted_documents, 167 bool hide_hosted_documents,
167 scoped_ptr<gdata::GDataEntryProtoVector> entries); 168 scoped_ptr<gdata::GDataEntryProtoVector> entries);
168 169
170 // Called when GetResourceIdsOfAllFilesOnUIThread() is complete.
171 void OnGetResourceIdsOfAllFiles(
172 const std::vector<std::string>& resource_ids);
173
174 // Called when GetCacheEntryOnUIThread() is complete.
175 void OnGetCacheEntry(const std::string& resource_id,
176 bool success,
177 const gdata::GDataCacheEntry& cache_entry);
178
179 // The number of pending ReadDirectoryByPath() calls.
180 int num_pending_reads_;
169 base::WeakPtrFactory<DriveInternalsWebUIHandler> weak_ptr_factory_; 181 base::WeakPtrFactory<DriveInternalsWebUIHandler> weak_ptr_factory_;
170 DISALLOW_COPY_AND_ASSIGN(DriveInternalsWebUIHandler); 182 DISALLOW_COPY_AND_ASSIGN(DriveInternalsWebUIHandler);
171 }; 183 };
172 184
173 void DriveInternalsWebUIHandler::RegisterMessages() { 185 void DriveInternalsWebUIHandler::RegisterMessages() {
174 web_ui()->RegisterMessageCallback( 186 web_ui()->RegisterMessageCallback(
175 "pageLoaded", 187 "pageLoaded",
176 base::Bind(&DriveInternalsWebUIHandler::OnPageLoaded, 188 base::Bind(&DriveInternalsWebUIHandler::OnPageLoaded,
177 weak_ptr_factory_.GetWeakPtr())); 189 weak_ptr_factory_.GetWeakPtr()));
178 } 190 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 DCHECK(gcache_contents); 230 DCHECK(gcache_contents);
219 web_ui()->CallJavascriptFunction("updateGCacheContents", *gcache_contents); 231 web_ui()->CallJavascriptFunction("updateGCacheContents", *gcache_contents);
220 232
221 // Start updating the file system tree section, if we have access token. 233 // Start updating the file system tree section, if we have access token.
222 gdata::GDataSystemService* system_service = GetSystemService(); 234 gdata::GDataSystemService* system_service = GetSystemService();
223 if (!system_service->docs_service()->HasAccessToken()) 235 if (!system_service->docs_service()->HasAccessToken())
224 return; 236 return;
225 237
226 // Start rendering the file system tree as text. 238 // Start rendering the file system tree as text.
227 const FilePath root_path = FilePath(gdata::kGDataRootDirectory); 239 const FilePath root_path = FilePath(gdata::kGDataRootDirectory);
240 ++num_pending_reads_;
228 system_service->file_system()->ReadDirectoryByPath( 241 system_service->file_system()->ReadDirectoryByPath(
229 root_path, 242 root_path,
230 base::Bind(&DriveInternalsWebUIHandler::OnReadDirectoryByPath, 243 base::Bind(&DriveInternalsWebUIHandler::OnReadDirectoryByPath,
231 weak_ptr_factory_.GetWeakPtr(), 244 weak_ptr_factory_.GetWeakPtr(),
232 root_path)); 245 root_path));
233 } 246 }
234 247
235 void DriveInternalsWebUIHandler::OnReadDirectoryByPath( 248 void DriveInternalsWebUIHandler::OnReadDirectoryByPath(
236 const FilePath& parent_path, 249 const FilePath& parent_path,
237 gdata::GDataFileError error, 250 gdata::GDataFileError error,
238 bool hide_hosted_documents, 251 bool hide_hosted_documents,
239 scoped_ptr<gdata::GDataEntryProtoVector> entries) { 252 scoped_ptr<gdata::GDataEntryProtoVector> entries) {
240 if (error != gdata::GDATA_FILE_OK) 253 --num_pending_reads_;
241 return; 254 if (error == gdata::GDATA_FILE_OK) {
242 DCHECK(entries.get()); 255 DCHECK(entries.get());
243 256
244 std::string file_system_as_text; 257 std::string file_system_as_text;
245 for (size_t i = 0; i < entries->size(); ++i) { 258 for (size_t i = 0; i < entries->size(); ++i) {
246 const gdata::GDataEntryProto& entry = (*entries)[i]; 259 const gdata::GDataEntryProto& entry = (*entries)[i];
247 const FilePath current_path = parent_path.Append( 260 const FilePath current_path = parent_path.Append(
248 FilePath::FromUTF8Unsafe(entry.base_name())); 261 FilePath::FromUTF8Unsafe(entry.base_name()));
249 262
250 file_system_as_text.append(FormatEntry(current_path, entry) + "\n"); 263 file_system_as_text.append(FormatEntry(current_path, entry) + "\n");
251 264
252 if (entry.file_info().is_directory()) { 265 if (entry.file_info().is_directory()) {
253 GetSystemService()->file_system()->ReadDirectoryByPath( 266 ++num_pending_reads_;
254 current_path, 267 GetSystemService()->file_system()->ReadDirectoryByPath(
255 base::Bind(&DriveInternalsWebUIHandler::OnReadDirectoryByPath, 268 current_path,
256 weak_ptr_factory_.GetWeakPtr(), 269 base::Bind(&DriveInternalsWebUIHandler::OnReadDirectoryByPath,
257 current_path)); 270 weak_ptr_factory_.GetWeakPtr(),
271 current_path));
272 }
258 } 273 }
274
275 // There may be pending ReadDirectoryByPath() calls, but we can update
276 // the page with what we have now. This results in progressive
277 // updates, which is good for a large file system.
278 const base::StringValue value(file_system_as_text);
279 web_ui()->CallJavascriptFunction("updateFileSystemContents", value);
259 } 280 }
260 281
261 // There may be pending ReadDirectoryByPath() calls, but we can update 282 // Start updating the cache contents section once all directories are
262 // the page with what we have now. This results in progressive 283 // processed.
263 // updates, which is good for a large file system. 284 if (num_pending_reads_ == 0) {
264 const base::StringValue value(file_system_as_text); 285 GetSystemService()->cache()->GetResourceIdsOfAllFilesOnUIThread(
265 web_ui()->CallJavascriptFunction("updateFileSystemContents", value); 286 base::Bind(&DriveInternalsWebUIHandler::OnGetResourceIdsOfAllFiles,
287 weak_ptr_factory_.GetWeakPtr()));
288 }
289 }
290
291 void DriveInternalsWebUIHandler::OnGetResourceIdsOfAllFiles(
292 const std::vector<std::string>& resource_ids) {
293 for (size_t i = 0; i < resource_ids.size(); ++i) {
294 const std::string& resource_id = resource_ids[i];
295 GetSystemService()->cache()->GetCacheEntryOnUIThread(
296 resource_id,
297 "", // Don't check MD5.
298 base::Bind(&DriveInternalsWebUIHandler::OnGetCacheEntry,
299 weak_ptr_factory_.GetWeakPtr(),
300 resource_id));
301 }
302 }
303
304 void DriveInternalsWebUIHandler::OnGetCacheEntry(
305 const std::string& resource_id,
306 bool success,
307 const gdata::GDataCacheEntry& cache_entry) {
308 if (!success) {
309 LOG(ERROR) << "Failed to get cache entry: " << resource_id;
310 return;
311 }
312
313 // Convert |cache_entry| into a dictionary.
314 base::DictionaryValue value;
315 value.SetString("resource_id", resource_id);
316 value.SetString("md5", cache_entry.md5());
317 value.SetBoolean("is_present", cache_entry.is_present());
318 value.SetBoolean("is_pinned", cache_entry.is_pinned());
319 value.SetBoolean("is_dirty", cache_entry.is_dirty());
320 value.SetBoolean("is_mounted", cache_entry.is_mounted());
321 value.SetBoolean("is_persistent", cache_entry.is_persistent());
322
323 web_ui()->CallJavascriptFunction("updateCacheContents", value);
266 } 324 }
267 325
268 } // namespace 326 } // namespace
269 327
270 DriveInternalsUI::DriveInternalsUI(content::WebUI* web_ui) 328 DriveInternalsUI::DriveInternalsUI(content::WebUI* web_ui)
271 : WebUIController(web_ui) { 329 : WebUIController(web_ui) {
272 web_ui->AddMessageHandler(new DriveInternalsWebUIHandler()); 330 web_ui->AddMessageHandler(new DriveInternalsWebUIHandler());
273 331
274 ChromeWebUIDataSource* source = 332 ChromeWebUIDataSource* source =
275 new ChromeWebUIDataSource(chrome::kChromeUIDriveInternalsHost); 333 new ChromeWebUIDataSource(chrome::kChromeUIDriveInternalsHost);
276 source->add_resource_path("drive_internals.css", IDR_DRIVE_INTERNALS_CSS); 334 source->add_resource_path("drive_internals.css", IDR_DRIVE_INTERNALS_CSS);
277 source->add_resource_path("drive_internals.js", IDR_DRIVE_INTERNALS_JS); 335 source->add_resource_path("drive_internals.js", IDR_DRIVE_INTERNALS_JS);
278 source->set_default_resource(IDR_DRIVE_INTERNALS_HTML); 336 source->set_default_resource(IDR_DRIVE_INTERNALS_HTML);
279 337
280 Profile* profile = Profile::FromWebUI(web_ui); 338 Profile* profile = Profile::FromWebUI(web_ui);
281 ChromeURLDataManager::AddDataSource(profile, source); 339 ChromeURLDataManager::AddDataSource(profile, source);
282 } 340 }
283 341
284 } // namespace chromeos 342 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/resources/chromeos/drive_internals.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698