Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "base/path_service.h" | |
| 13 #include "base/sys_info.h" | |
| 12 #include "chrome/browser/chromeos/gdata/gdata.pb.h" | 14 #include "chrome/browser/chromeos/gdata/gdata.pb.h" |
| 13 #include "chrome/browser/chromeos/gdata/gdata_auth_service.h" | 15 #include "chrome/browser/chromeos/gdata/gdata_auth_service.h" |
| 14 #include "chrome/browser/chromeos/gdata/gdata_cache.h" | 16 #include "chrome/browser/chromeos/gdata/gdata_cache.h" |
| 15 #include "chrome/browser/chromeos/gdata/gdata_documents_service.h" | 17 #include "chrome/browser/chromeos/gdata/gdata_documents_service.h" |
| 16 #include "chrome/browser/chromeos/gdata/gdata_file_system_interface.h" | 18 #include "chrome/browser/chromeos/gdata/gdata_file_system_interface.h" |
| 17 #include "chrome/browser/chromeos/gdata/gdata_system_service.h" | 19 #include "chrome/browser/chromeos/gdata/gdata_system_service.h" |
| 18 #include "chrome/browser/chromeos/gdata/gdata_util.h" | 20 #include "chrome/browser/chromeos/gdata/gdata_util.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" | 22 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
| 21 #include "chrome/common/url_constants.h" | 23 #include "chrome/common/url_constants.h" |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 190 "pageLoaded", | 192 "pageLoaded", |
| 191 base::Bind(&DriveInternalsWebUIHandler::OnPageLoaded, | 193 base::Bind(&DriveInternalsWebUIHandler::OnPageLoaded, |
| 192 weak_ptr_factory_.GetWeakPtr())); | 194 weak_ptr_factory_.GetWeakPtr())); |
| 193 } | 195 } |
| 194 | 196 |
| 195 gdata::GDataSystemService* DriveInternalsWebUIHandler::GetSystemService() { | 197 gdata::GDataSystemService* DriveInternalsWebUIHandler::GetSystemService() { |
| 196 Profile* profile = Profile::FromWebUI(web_ui()); | 198 Profile* profile = Profile::FromWebUI(web_ui()); |
| 197 return gdata::GDataSystemServiceFactory::GetForProfile(profile); | 199 return gdata::GDataSystemServiceFactory::GetForProfile(profile); |
| 198 } | 200 } |
| 199 | 201 |
| 200 void DriveInternalsWebUIHandler::OnPageLoaded(const base::ListValue* args) { | 202 void DriveInternalsWebUIHandler::OnPageLoaded(const base::ListValue* args) { |
|
satorux1
2012/08/13 07:26:20
Please add the following here followed by a blank
Haruki Sato
2012/08/17 05:46:34
Done.
| |
| 201 gdata::GDataSystemService* system_service = GetSystemService(); | 203 gdata::GDataSystemService* system_service = GetSystemService(); |
| 202 // |system_service| may be NULL in the guest/incognito mode. | 204 // |system_service| may be NULL in the guest/incognito mode. |
| 203 if (!system_service) | 205 if (!system_service) |
| 204 return; | 206 return; |
| 205 | 207 |
| 206 gdata::DocumentsServiceInterface* documents_service = | 208 gdata::DocumentsServiceInterface* documents_service = |
| 207 system_service->docs_service(); | 209 system_service->docs_service(); |
| 208 DCHECK(documents_service); | 210 DCHECK(documents_service); |
| 209 | 211 |
| 210 // Update the auth status section. | 212 // Update the auth status section. |
| 211 base::DictionaryValue auth_status; | 213 base::DictionaryValue auth_status; |
| 212 auth_status.SetBoolean("has-refresh-token", | 214 auth_status.SetBoolean("has-refresh-token", |
| 213 documents_service->HasRefreshToken()); | 215 documents_service->HasRefreshToken()); |
| 214 auth_status.SetBoolean("has-access-token", | 216 auth_status.SetBoolean("has-access-token", |
| 215 documents_service->HasAccessToken()); | 217 documents_service->HasAccessToken()); |
| 216 web_ui()->CallJavascriptFunction("updateAuthStatus", auth_status); | 218 web_ui()->CallJavascriptFunction("updateAuthStatus", auth_status); |
| 217 | 219 |
| 220 // Propagate the amount of local free space in bytes. | |
| 221 FilePath path; | |
| 222 int64 free_space = -1; | |
| 223 if (PathService::Get(base::DIR_HOME, &path)) { | |
| 224 free_space = base::SysInfo::AmountOfFreeDiskSpace(path); | |
|
satorux1
2012/08/13 07:26:20
I think we shouldn't do this on UI thread. We shou
Haruki Sato
2012/08/17 05:46:34
Done.
and moved the code to have more cleaner stru
| |
| 225 } else { | |
| 226 LOG(ERROR) << "Home directory not found"; | |
| 227 } | |
| 228 base::DictionaryValue local_storage_summary; | |
| 229 local_storage_summary.SetDouble("free_space", free_space); | |
| 230 web_ui()->CallJavascriptFunction( | |
| 231 "updateLocalStorageUsage", local_storage_summary); | |
| 232 | |
| 233 | |
| 218 // Start updating the GCache contents section. | 234 // Start updating the GCache contents section. |
| 219 Profile* profile = Profile::FromWebUI(web_ui()); | 235 Profile* profile = Profile::FromWebUI(web_ui()); |
| 220 const FilePath root_path = | 236 const FilePath root_path = |
| 221 gdata::GDataCache::GetCacheRootPath(profile); | 237 gdata::GDataCache::GetCacheRootPath(profile); |
| 222 base::ListValue* gcache_contents = new ListValue; | 238 base::ListValue* gcache_contents = new ListValue; |
| 223 base::DictionaryValue* gcache_summary = new DictionaryValue; | 239 base::DictionaryValue* gcache_summary = new DictionaryValue; |
| 224 content::BrowserThread::PostBlockingPoolTaskAndReply( | 240 content::BrowserThread::PostBlockingPoolTaskAndReply( |
| 225 FROM_HERE, | 241 FROM_HERE, |
| 226 base::Bind(&GetGCacheContents, | 242 base::Bind(&GetGCacheContents, |
| 227 root_path, | 243 root_path, |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 345 new ChromeWebUIDataSource(chrome::kChromeUIDriveInternalsHost); | 361 new ChromeWebUIDataSource(chrome::kChromeUIDriveInternalsHost); |
| 346 source->add_resource_path("drive_internals.css", IDR_DRIVE_INTERNALS_CSS); | 362 source->add_resource_path("drive_internals.css", IDR_DRIVE_INTERNALS_CSS); |
| 347 source->add_resource_path("drive_internals.js", IDR_DRIVE_INTERNALS_JS); | 363 source->add_resource_path("drive_internals.js", IDR_DRIVE_INTERNALS_JS); |
| 348 source->set_default_resource(IDR_DRIVE_INTERNALS_HTML); | 364 source->set_default_resource(IDR_DRIVE_INTERNALS_HTML); |
| 349 | 365 |
| 350 Profile* profile = Profile::FromWebUI(web_ui); | 366 Profile* profile = Profile::FromWebUI(web_ui); |
| 351 ChromeURLDataManager::AddDataSource(profile, source); | 367 ChromeURLDataManager::AddDataSource(profile, source); |
| 352 } | 368 } |
| 353 | 369 |
| 354 } // namespace chromeos | 370 } // namespace chromeos |
| OLD | NEW |