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

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

Issue 296003012: [fsp] Introduce chrome://fsp-internals for logging and debugging. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased + addressed comments. Created 6 years, 7 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
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/webui/chromeos/fsp_internals_ui.h"
6
7 #include "base/bind.h"
8 #include "base/memory/weak_ptr.h"
9 #include "base/values.h"
10 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info .h"
11 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte rface.h"
12 #include "chrome/browser/chromeos/file_system_provider/request_manager.h"
13 #include "chrome/browser/chromeos/file_system_provider/service.h"
14 #include "chrome/browser/chromeos/file_system_provider/service_factory.h"
15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/common/url_constants.h"
17 #include "content/public/browser/browser_thread.h"
18 #include "content/public/browser/web_ui.h"
19 #include "content/public/browser/web_ui_data_source.h"
20 #include "content/public/browser/web_ui_message_handler.h"
21 #include "grit/browser_resources.h"
22
23 using content::BrowserThread;
24
25 namespace chromeos {
26
27 namespace {
28
29 // Class to handle messages from chrome://fsp-internals.
30 class FSPInternalsWebUIHandler : public content::WebUIMessageHandler {
31 public:
32 FSPInternalsWebUIHandler() : weak_ptr_factory_(this) {}
33
34 virtual ~FSPInternalsWebUIHandler() {}
35
36 private:
37 // content::WebUIMessageHandler overrides.
38 virtual void RegisterMessages() OVERRIDE;
39
40 // Gets a file system provider service for the current profile. If not found,
41 // then NULL.
42 file_system_provider::Service* GetService();
43
44 // Invoked when updating file system list is requested.
45 void OnUpdateFileSystems(const base::ListValue* args);
46
47 base::WeakPtrFactory<FSPInternalsWebUIHandler> weak_ptr_factory_;
48 DISALLOW_COPY_AND_ASSIGN(FSPInternalsWebUIHandler);
Nikita (slow) 2014/05/23 15:33:52 nit: Insert one empty line.
mtomasz 2014/05/26 00:34:31 Done.
49 };
50
51 void FSPInternalsWebUIHandler::RegisterMessages() {
52 web_ui()->RegisterMessageCallback(
53 "updateFileSystems",
54 base::Bind(&FSPInternalsWebUIHandler::OnUpdateFileSystems,
55 weak_ptr_factory_.GetWeakPtr()));
56 }
57
58 file_system_provider::Service* FSPInternalsWebUIHandler::GetService() {
59 DCHECK_CURRENTLY_ON(BrowserThread::UI);
60
61 Profile* const profile = Profile::FromWebUI(web_ui());
62 return file_system_provider::ServiceFactory::FindExisting(profile);
63 }
64
65 void FSPInternalsWebUIHandler::OnUpdateFileSystems(
66 const base::ListValue* args) {
67 DCHECK_CURRENTLY_ON(BrowserThread::UI);
68
69 file_system_provider::Service* const service = GetService();
70 if (!service)
71 return;
72
73 base::ListValue items;
74
75 const std::vector<file_system_provider::ProvidedFileSystemInfo>
76 file_system_info_list = service->GetProvidedFileSystemInfoList();
77
78 for (size_t i = 0; i < file_system_info_list.size(); ++i) {
79 const file_system_provider::ProvidedFileSystemInfo file_system_info =
80 file_system_info_list[i];
81
82 file_system_provider::ProvidedFileSystemInterface* const file_system =
83 service->GetProvidedFileSystem(file_system_info.extension_id(),
84 file_system_info.file_system_id());
85 DCHECK(file_system);
86
87 file_system_provider::RequestManager* const request_manager =
88 file_system->GetRequestManager();
89 DCHECK(request_manager);
90
91 base::DictionaryValue* item_value = new base::DictionaryValue();
92 item_value->SetString("id", file_system_info.file_system_id());
93 item_value->SetString("name", file_system_info.file_system_name());
94 item_value->SetString("extensionId", file_system_info.extension_id());
95 item_value->SetString("mountPath",
96 file_system_info.mount_path().AsUTF8Unsafe());
97 item_value->SetInteger("activeRequests",
98 request_manager->GetActiveRequestsForLogging());
99
100 items.Append(item_value);
101 }
102
103 web_ui()->CallJavascriptFunction("updateFileSystems", items);
104 }
105
106 } // namespace
107
108 FSPInternalsUI::FSPInternalsUI(content::WebUI* web_ui)
109 : WebUIController(web_ui) {
110 web_ui->AddMessageHandler(new FSPInternalsWebUIHandler());
111
112 content::WebUIDataSource* source =
113 content::WebUIDataSource::Create(chrome::kChromeUIFSPInternalsHost);
114 source->AddResourcePath("fsp_internals.css", IDR_FSP_INTERNALS_CSS);
115 source->AddResourcePath("fsp_internals.js", IDR_FSP_INTERNALS_JS);
116 source->SetDefaultResource(IDR_FSP_INTERNALS_HTML);
117
118 Profile* profile = Profile::FromWebUI(web_ui);
119 content::WebUIDataSource::Add(profile, source);
120 }
121
122 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698