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_(""), | |
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 drive::EventLogger::Event last_sent_event_; | |
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 size_t start = 0; | |
551 for (size_t i = 0; i < log.size(); ++i) { | |
552 if (log[i].when == last_sent_event_.when && | |
553 log[i].what == last_sent_event_.what) { | |
satorux1
2012/11/14 05:55:11
This looks tricky. What about introducing a monoto
kinaba
2012/11/14 06:19:52
Done.
| |
554 start = i+1; | |
555 break; | |
556 } | |
557 } | |
558 | |
559 if (start < log.size()) { | |
560 base::ListValue list; | |
561 for (size_t i = start; i < log.size(); ++i) { | |
562 base::DictionaryValue* dict = new DictionaryValue; | |
563 dict->SetString("key", | |
564 google_apis::util::FormatTimeAsStringLocaltime(log[i].when)); | |
565 dict->SetString("value", log[i].what); | |
566 list.Append(dict); | |
567 } | |
568 last_sent_event_ = log.back(); | |
569 web_ui()->CallJavascriptFunction("updateEventLog", list); | |
570 } | |
571 } | |
572 | |
538 void DriveInternalsWebUIHandler::OnGetGCacheContents( | 573 void DriveInternalsWebUIHandler::OnGetGCacheContents( |
539 base::ListValue* gcache_contents, | 574 base::ListValue* gcache_contents, |
540 base::DictionaryValue* gcache_summary) { | 575 base::DictionaryValue* gcache_summary) { |
541 DCHECK(gcache_contents); | 576 DCHECK(gcache_contents); |
542 DCHECK(gcache_summary); | 577 DCHECK(gcache_summary); |
543 web_ui()->CallJavascriptFunction("updateGCacheContents", | 578 web_ui()->CallJavascriptFunction("updateGCacheContents", |
544 *gcache_contents, | 579 *gcache_contents, |
545 *gcache_summary); | 580 *gcache_summary); |
546 } | 581 } |
547 | 582 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
623 drive::DriveSystemService* system_service = GetSystemService(); | 658 drive::DriveSystemService* system_service = GetSystemService(); |
624 // |system_service| may be NULL in the guest/incognito mode. | 659 // |system_service| may be NULL in the guest/incognito mode. |
625 if (!system_service) | 660 if (!system_service) |
626 return; | 661 return; |
627 | 662 |
628 google_apis::DriveServiceInterface* drive_service = | 663 google_apis::DriveServiceInterface* drive_service = |
629 system_service->drive_service(); | 664 system_service->drive_service(); |
630 DCHECK(drive_service); | 665 DCHECK(drive_service); |
631 | 666 |
632 UpdateInFlightOperationsSection(drive_service); | 667 UpdateInFlightOperationsSection(drive_service); |
668 UpdateEventLogSection(system_service->event_logger()); | |
633 } | 669 } |
634 | 670 |
635 } // namespace | 671 } // namespace |
636 | 672 |
637 DriveInternalsUI::DriveInternalsUI(content::WebUI* web_ui) | 673 DriveInternalsUI::DriveInternalsUI(content::WebUI* web_ui) |
638 : WebUIController(web_ui) { | 674 : WebUIController(web_ui) { |
639 web_ui->AddMessageHandler(new DriveInternalsWebUIHandler()); | 675 web_ui->AddMessageHandler(new DriveInternalsWebUIHandler()); |
640 | 676 |
641 ChromeWebUIDataSource* source = | 677 ChromeWebUIDataSource* source = |
642 new ChromeWebUIDataSource(chrome::kChromeUIDriveInternalsHost); | 678 new ChromeWebUIDataSource(chrome::kChromeUIDriveInternalsHost); |
643 source->add_resource_path("drive_internals.css", IDR_DRIVE_INTERNALS_CSS); | 679 source->add_resource_path("drive_internals.css", IDR_DRIVE_INTERNALS_CSS); |
644 source->add_resource_path("drive_internals.js", IDR_DRIVE_INTERNALS_JS); | 680 source->add_resource_path("drive_internals.js", IDR_DRIVE_INTERNALS_JS); |
645 source->set_default_resource(IDR_DRIVE_INTERNALS_HTML); | 681 source->set_default_resource(IDR_DRIVE_INTERNALS_HTML); |
646 | 682 |
647 Profile* profile = Profile::FromWebUI(web_ui); | 683 Profile* profile = Profile::FromWebUI(web_ui); |
648 ChromeURLDataManager::AddDataSource(profile, source); | 684 ChromeURLDataManager::AddDataSource(profile, source); |
649 } | 685 } |
650 | 686 |
651 } // namespace chromeos | 687 } // namespace chromeos |
OLD | NEW |