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/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
11 #include "base/memory/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
14 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
15 #include "base/sys_info.h" | 15 #include "base/sys_info.h" |
16 #include "chrome/browser/chromeos/drive/drive.pb.h" | 16 #include "chrome/browser/chromeos/drive/drive.pb.h" |
17 #include "chrome/browser/chromeos/drive/drive_cache.h" | 17 #include "chrome/browser/chromeos/drive/drive_cache.h" |
18 #include "chrome/browser/chromeos/drive/drive_file_system_interface.h" | 18 #include "chrome/browser/chromeos/drive/drive_file_system_interface.h" |
19 #include "chrome/browser/chromeos/drive/drive_resource_metadata.h" | 19 #include "chrome/browser/chromeos/drive/drive_resource_metadata.h" |
20 #include "chrome/browser/chromeos/drive/drive_system_service.h" | 20 #include "chrome/browser/chromeos/drive/drive_system_service.h" |
| 21 #include "chrome/browser/chromeos/drive/event_logger.h" |
21 #include "chrome/browser/google_apis/auth_service.h" | 22 #include "chrome/browser/google_apis/auth_service.h" |
22 #include "chrome/browser/google_apis/drive_api_parser.h" | 23 #include "chrome/browser/google_apis/drive_api_parser.h" |
23 #include "chrome/browser/google_apis/drive_service_interface.h" | 24 #include "chrome/browser/google_apis/drive_service_interface.h" |
24 #include "chrome/browser/google_apis/gdata_errorcode.h" | 25 #include "chrome/browser/google_apis/gdata_errorcode.h" |
25 #include "chrome/browser/google_apis/gdata_util.h" | 26 #include "chrome/browser/google_apis/gdata_util.h" |
26 #include "chrome/browser/google_apis/gdata_wapi_parser.h" | 27 #include "chrome/browser/google_apis/gdata_wapi_parser.h" |
27 #include "chrome/browser/prefs/pref_service.h" | 28 #include "chrome/browser/prefs/pref_service.h" |
28 #include "chrome/browser/profiles/profile.h" | 29 #include "chrome/browser/profiles/profile.h" |
29 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" | 30 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
30 #include "chrome/common/chrome_switches.h" | 31 #include "chrome/common/chrome_switches.h" |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 } | 163 } |
163 | 164 |
164 return out; | 165 return out; |
165 } | 166 } |
166 | 167 |
167 // Class to handle messages from chrome://drive-internals. | 168 // Class to handle messages from chrome://drive-internals. |
168 class DriveInternalsWebUIHandler : public content::WebUIMessageHandler { | 169 class DriveInternalsWebUIHandler : public content::WebUIMessageHandler { |
169 public: | 170 public: |
170 DriveInternalsWebUIHandler() | 171 DriveInternalsWebUIHandler() |
171 : num_pending_reads_(0), | 172 : num_pending_reads_(0), |
| 173 last_sent_event_id_(-1), |
172 weak_ptr_factory_(this) { | 174 weak_ptr_factory_(this) { |
173 } | 175 } |
174 | 176 |
175 virtual ~DriveInternalsWebUIHandler() { | 177 virtual ~DriveInternalsWebUIHandler() { |
176 } | 178 } |
177 | 179 |
178 private: | 180 private: |
179 // WebUIMessageHandler override. | 181 // WebUIMessageHandler override. |
180 virtual void RegisterMessages() OVERRIDE; | 182 virtual void RegisterMessages() OVERRIDE; |
181 | 183 |
(...skipping 13 matching lines...) Expand all Loading... |
195 void UpdateLocalMetadataSection( | 197 void UpdateLocalMetadataSection( |
196 google_apis::DriveServiceInterface* drive_service); | 198 google_apis::DriveServiceInterface* drive_service); |
197 void UpdateDeltaUpdateStatusSection(); | 199 void UpdateDeltaUpdateStatusSection(); |
198 void UpdateInFlightOperationsSection( | 200 void UpdateInFlightOperationsSection( |
199 google_apis::DriveServiceInterface* drive_service); | 201 google_apis::DriveServiceInterface* drive_service); |
200 void UpdateGCacheContentsSection(); | 202 void UpdateGCacheContentsSection(); |
201 void UpdateFileSystemContentsSection( | 203 void UpdateFileSystemContentsSection( |
202 google_apis::DriveServiceInterface* drive_service); | 204 google_apis::DriveServiceInterface* drive_service); |
203 void UpdateLocalStorageUsageSection(); | 205 void UpdateLocalStorageUsageSection(); |
204 void UpdateCacheContentsSection(drive::DriveCache* cache); | 206 void UpdateCacheContentsSection(drive::DriveCache* cache); |
| 207 void UpdateEventLogSection(drive::EventLogger* event_logger); |
205 | 208 |
206 // Called when GetGCacheContents() is complete. | 209 // Called when GetGCacheContents() is complete. |
207 void OnGetGCacheContents(base::ListValue* gcache_contents, | 210 void OnGetGCacheContents(base::ListValue* gcache_contents, |
208 base::DictionaryValue* cache_summary); | 211 base::DictionaryValue* cache_summary); |
209 | 212 |
210 // Called when GetEntryInfoByPath() is complete. | 213 // Called when GetEntryInfoByPath() is complete. |
211 void OnGetEntryInfoByPath(const FilePath& path, | 214 void OnGetEntryInfoByPath(const FilePath& path, |
212 drive::DriveFileError error, | 215 drive::DriveFileError error, |
213 scoped_ptr<drive::DriveEntryProto> entry); | 216 scoped_ptr<drive::DriveEntryProto> entry); |
214 | 217 |
(...skipping 12 matching lines...) Expand all Loading... |
227 | 230 |
228 // Called when GetAccountMetadata() call to DriveService is complete. | 231 // Called when GetAccountMetadata() call to DriveService is complete. |
229 void OnGetAccountMetadata(google_apis::GDataErrorCode status, | 232 void OnGetAccountMetadata(google_apis::GDataErrorCode status, |
230 scoped_ptr<base::Value> data); | 233 scoped_ptr<base::Value> data); |
231 | 234 |
232 // Called when the page requests periodic update. | 235 // Called when the page requests periodic update. |
233 void OnPeriodicUpdate(const base::ListValue* args); | 236 void OnPeriodicUpdate(const base::ListValue* args); |
234 | 237 |
235 // The number of pending ReadDirectoryByPath() calls. | 238 // The number of pending ReadDirectoryByPath() calls. |
236 int num_pending_reads_; | 239 int num_pending_reads_; |
| 240 // The last event sent to the JavaScript side. |
| 241 int last_sent_event_id_; |
| 242 |
237 base::WeakPtrFactory<DriveInternalsWebUIHandler> weak_ptr_factory_; | 243 base::WeakPtrFactory<DriveInternalsWebUIHandler> weak_ptr_factory_; |
238 DISALLOW_COPY_AND_ASSIGN(DriveInternalsWebUIHandler); | 244 DISALLOW_COPY_AND_ASSIGN(DriveInternalsWebUIHandler); |
239 }; | 245 }; |
240 | 246 |
241 void DriveInternalsWebUIHandler::OnGetAccountMetadata( | 247 void DriveInternalsWebUIHandler::OnGetAccountMetadata( |
242 google_apis::GDataErrorCode status, scoped_ptr<base::Value> data) { | 248 google_apis::GDataErrorCode status, scoped_ptr<base::Value> data) { |
243 if (status != google_apis::HTTP_SUCCESS) { | 249 if (status != google_apis::HTTP_SUCCESS) { |
244 LOG(ERROR) << "Failed to get account metadata"; | 250 LOG(ERROR) << "Failed to get account metadata"; |
245 return; | 251 return; |
246 } | 252 } |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 UpdateDriveRelatedPreferencesSection(); | 329 UpdateDriveRelatedPreferencesSection(); |
324 UpdateAuthStatusSection(drive_service); | 330 UpdateAuthStatusSection(drive_service); |
325 UpdateAccountMetadataSection(drive_service); | 331 UpdateAccountMetadataSection(drive_service); |
326 UpdateLocalMetadataSection(drive_service); | 332 UpdateLocalMetadataSection(drive_service); |
327 UpdateDeltaUpdateStatusSection(); | 333 UpdateDeltaUpdateStatusSection(); |
328 UpdateInFlightOperationsSection(drive_service); | 334 UpdateInFlightOperationsSection(drive_service); |
329 UpdateGCacheContentsSection(); | 335 UpdateGCacheContentsSection(); |
330 UpdateFileSystemContentsSection(drive_service); | 336 UpdateFileSystemContentsSection(drive_service); |
331 UpdateCacheContentsSection(cache); | 337 UpdateCacheContentsSection(cache); |
332 UpdateLocalStorageUsageSection(); | 338 UpdateLocalStorageUsageSection(); |
| 339 UpdateEventLogSection(system_service->event_logger()); |
333 } | 340 } |
334 | 341 |
335 void DriveInternalsWebUIHandler::UpdateDriveRelatedFlagsSection() { | 342 void DriveInternalsWebUIHandler::UpdateDriveRelatedFlagsSection() { |
336 const char* kDriveRelatedFlags[] = { | 343 const char* kDriveRelatedFlags[] = { |
337 switches::kDisableDrive, | 344 switches::kDisableDrive, |
338 switches::kDisableDrivePrefetch, | 345 switches::kDisableDrivePrefetch, |
339 switches::kEnableDriveV2Api, | 346 switches::kEnableDriveV2Api, |
340 }; | 347 }; |
341 | 348 |
342 base::ListValue flags; | 349 base::ListValue flags; |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 } | 535 } |
529 } | 536 } |
530 | 537 |
531 void DriveInternalsWebUIHandler::UpdateCacheContentsSection( | 538 void DriveInternalsWebUIHandler::UpdateCacheContentsSection( |
532 drive::DriveCache* cache) { | 539 drive::DriveCache* cache) { |
533 cache->Iterate(base::Bind(&DriveInternalsWebUIHandler::UpdateCacheEntry, | 540 cache->Iterate(base::Bind(&DriveInternalsWebUIHandler::UpdateCacheEntry, |
534 weak_ptr_factory_.GetWeakPtr()), | 541 weak_ptr_factory_.GetWeakPtr()), |
535 base::Bind(&base::DoNothing)); | 542 base::Bind(&base::DoNothing)); |
536 } | 543 } |
537 | 544 |
| 545 void DriveInternalsWebUIHandler::UpdateEventLogSection( |
| 546 drive::EventLogger* event_logger) { |
| 547 const std::deque<drive::EventLogger::Event>& log = |
| 548 event_logger->history(); |
| 549 |
| 550 base::ListValue list; |
| 551 for (size_t i = 0; i < log.size(); ++i) { |
| 552 // Skip events which were already sent. |
| 553 if (log[i].id <= last_sent_event_id_) |
| 554 continue; |
| 555 |
| 556 base::DictionaryValue* dict = new DictionaryValue; |
| 557 dict->SetString("key", |
| 558 google_apis::util::FormatTimeAsStringLocaltime(log[i].when)); |
| 559 dict->SetString("value", log[i].what); |
| 560 list.Append(dict); |
| 561 last_sent_event_id_ = log[i].id; |
| 562 } |
| 563 if (!list.empty()) |
| 564 web_ui()->CallJavascriptFunction("updateEventLog", list); |
| 565 } |
| 566 |
538 void DriveInternalsWebUIHandler::OnGetGCacheContents( | 567 void DriveInternalsWebUIHandler::OnGetGCacheContents( |
539 base::ListValue* gcache_contents, | 568 base::ListValue* gcache_contents, |
540 base::DictionaryValue* gcache_summary) { | 569 base::DictionaryValue* gcache_summary) { |
541 DCHECK(gcache_contents); | 570 DCHECK(gcache_contents); |
542 DCHECK(gcache_summary); | 571 DCHECK(gcache_summary); |
543 web_ui()->CallJavascriptFunction("updateGCacheContents", | 572 web_ui()->CallJavascriptFunction("updateGCacheContents", |
544 *gcache_contents, | 573 *gcache_contents, |
545 *gcache_summary); | 574 *gcache_summary); |
546 } | 575 } |
547 | 576 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
623 drive::DriveSystemService* system_service = GetSystemService(); | 652 drive::DriveSystemService* system_service = GetSystemService(); |
624 // |system_service| may be NULL in the guest/incognito mode. | 653 // |system_service| may be NULL in the guest/incognito mode. |
625 if (!system_service) | 654 if (!system_service) |
626 return; | 655 return; |
627 | 656 |
628 google_apis::DriveServiceInterface* drive_service = | 657 google_apis::DriveServiceInterface* drive_service = |
629 system_service->drive_service(); | 658 system_service->drive_service(); |
630 DCHECK(drive_service); | 659 DCHECK(drive_service); |
631 | 660 |
632 UpdateInFlightOperationsSection(drive_service); | 661 UpdateInFlightOperationsSection(drive_service); |
| 662 UpdateEventLogSection(system_service->event_logger()); |
633 } | 663 } |
634 | 664 |
635 } // namespace | 665 } // namespace |
636 | 666 |
637 DriveInternalsUI::DriveInternalsUI(content::WebUI* web_ui) | 667 DriveInternalsUI::DriveInternalsUI(content::WebUI* web_ui) |
638 : WebUIController(web_ui) { | 668 : WebUIController(web_ui) { |
639 web_ui->AddMessageHandler(new DriveInternalsWebUIHandler()); | 669 web_ui->AddMessageHandler(new DriveInternalsWebUIHandler()); |
640 | 670 |
641 ChromeWebUIDataSource* source = | 671 ChromeWebUIDataSource* source = |
642 new ChromeWebUIDataSource(chrome::kChromeUIDriveInternalsHost); | 672 new ChromeWebUIDataSource(chrome::kChromeUIDriveInternalsHost); |
643 source->add_resource_path("drive_internals.css", IDR_DRIVE_INTERNALS_CSS); | 673 source->add_resource_path("drive_internals.css", IDR_DRIVE_INTERNALS_CSS); |
644 source->add_resource_path("drive_internals.js", IDR_DRIVE_INTERNALS_JS); | 674 source->add_resource_path("drive_internals.js", IDR_DRIVE_INTERNALS_JS); |
645 source->set_default_resource(IDR_DRIVE_INTERNALS_HTML); | 675 source->set_default_resource(IDR_DRIVE_INTERNALS_HTML); |
646 | 676 |
647 Profile* profile = Profile::FromWebUI(web_ui); | 677 Profile* profile = Profile::FromWebUI(web_ui); |
648 ChromeURLDataManager::AddDataSource(profile, source); | 678 ChromeURLDataManager::AddDataSource(profile, source); |
649 } | 679 } |
650 | 680 |
651 } // namespace chromeos | 681 } // namespace chromeos |
OLD | NEW |