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

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

Issue 301873002: [fsp] Show request logs in chrome://provided-file-systems. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Display errors as text. Created 6 years, 6 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/provided_file_systems.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 2014 The Chromium Authors. All rights reserved. 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 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/provided_file_systems_ui.h" 5 #include "chrome/browser/ui/webui/chromeos/provided_file_systems_ui.h"
6 6
7 #include <string>
7 #include <vector> 8 #include <vector>
8 9
9 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/files/file.h"
10 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
11 #include "base/values.h" 13 #include "base/values.h"
12 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info .h" 14 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info .h"
13 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte rface.h" 15 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte rface.h"
14 #include "chrome/browser/chromeos/file_system_provider/request_manager.h" 16 #include "chrome/browser/chromeos/file_system_provider/request_manager.h"
15 #include "chrome/browser/chromeos/file_system_provider/service.h" 17 #include "chrome/browser/chromeos/file_system_provider/service.h"
16 #include "chrome/browser/chromeos/file_system_provider/service_factory.h" 18 #include "chrome/browser/chromeos/file_system_provider/service_factory.h"
17 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/common/url_constants.h" 20 #include "chrome/common/url_constants.h"
19 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
20 #include "content/public/browser/web_ui.h" 22 #include "content/public/browser/web_ui.h"
21 #include "content/public/browser/web_ui_data_source.h" 23 #include "content/public/browser/web_ui_data_source.h"
22 #include "content/public/browser/web_ui_message_handler.h" 24 #include "content/public/browser/web_ui_message_handler.h"
23 #include "grit/browser_resources.h" 25 #include "grit/browser_resources.h"
24 26
25 using content::BrowserThread; 27 using content::BrowserThread;
26 28
27 namespace chromeos { 29 namespace chromeos {
28 30
29 namespace { 31 namespace {
30 32
31 // Class to handle messages from chrome://provided-file-systems. 33 // Class to handle messages from chrome://provided-file-systems.
32 class ProvidedFileSystemsWebUIHandler : public content::WebUIMessageHandler { 34 class ProvidedFileSystemsWebUIHandler
35 : public content::WebUIMessageHandler,
36 public file_system_provider::RequestManager::Observer {
33 public: 37 public:
34 ProvidedFileSystemsWebUIHandler() : weak_ptr_factory_(this) {} 38 ProvidedFileSystemsWebUIHandler() : weak_ptr_factory_(this) {}
35 39
36 virtual ~ProvidedFileSystemsWebUIHandler() {} 40 virtual ~ProvidedFileSystemsWebUIHandler();
41
42 // RequestManager::Observer overrides.
43 virtual void OnRequestCreated(
44 int request_id,
45 file_system_provider::RequestType type) OVERRIDE;
46 virtual void OnRequestDestroyed(int request_id) OVERRIDE;
47 virtual void OnRequestExecuted(int request_id) OVERRIDE;
48 virtual void OnRequestFulfilled(int request_id, bool has_more) OVERRIDE;
49 virtual void OnRequestRejected(int request_id,
50 base::File::Error error) OVERRIDE;
51 virtual void OnRequestTimeouted(int request_id) OVERRIDE;
37 52
38 private: 53 private:
39 // content::WebUIMessageHandler overrides. 54 // content::WebUIMessageHandler overrides.
40 virtual void RegisterMessages() OVERRIDE; 55 virtual void RegisterMessages() OVERRIDE;
41 56
42 // Gets a file system provider service for the current profile. If not found, 57 // Gets a file system provider service for the current profile. If not found,
43 // then NULL. 58 // then NULL.
44 file_system_provider::Service* GetService(); 59 file_system_provider::Service* GetService();
45 60
46 // Invoked when updating file system list is requested. 61 // Invoked when updating file system list is requested.
47 void OnUpdateFileSystems(const base::ListValue* args); 62 void UpdateFileSystems(const base::ListValue* args);
48 63
64 // Invoked when a file system is selected from the list.
65 void SelectFileSystem(const base::ListValue* args);
66
67 std::string selected_extension_id;
68 std::string selected_file_system_id;
49 base::WeakPtrFactory<ProvidedFileSystemsWebUIHandler> weak_ptr_factory_; 69 base::WeakPtrFactory<ProvidedFileSystemsWebUIHandler> weak_ptr_factory_;
50 70
51 DISALLOW_COPY_AND_ASSIGN(ProvidedFileSystemsWebUIHandler); 71 DISALLOW_COPY_AND_ASSIGN(ProvidedFileSystemsWebUIHandler);
52 }; 72 };
53 73
74 ProvidedFileSystemsWebUIHandler::~ProvidedFileSystemsWebUIHandler() {
75 // Stop observing the currently selected file system.
76 file_system_provider::Service* const service = GetService();
77 if (!service)
78 return;
79
80 file_system_provider::ProvidedFileSystemInterface* const file_system =
81 service->GetProvidedFileSystem(selected_extension_id,
82 selected_file_system_id);
83
84 if (file_system) {
85 file_system_provider::RequestManager* const request_manager =
86 file_system->GetRequestManager();
87 DCHECK(request_manager);
88 request_manager->RemoveObserver(this);
Nikita (slow) 2014/05/30 07:15:10 nit: Just file_system->GetRequestManager()->Remove
mtomasz 2014/06/02 03:16:24 This doesn't happen now, but theoretically Provide
Nikita (slow) 2014/06/02 06:15:12 Either way it will crash if you try to access it b
89 }
90 }
91
92 void ProvidedFileSystemsWebUIHandler::OnRequestCreated(
93 int request_id,
94 file_system_provider::RequestType type) {
95 base::DictionaryValue event;
96 event.SetInteger("id", request_id);
Nikita (slow) 2014/05/30 07:15:10 nit: Please extract all IDs as constants, they're
mtomasz 2014/06/02 03:16:24 Done.
97 event.SetString("eventType", "created");
98 event.SetString("requestType",
99 file_system_provider::RequestTypeToString(type));
100 event.SetDouble("time", base::Time::Now().ToJsTime());
101 web_ui()->CallJavascriptFunction("onRequestEvent", event);
102 }
103
104 void ProvidedFileSystemsWebUIHandler::OnRequestDestroyed(int request_id) {
105 base::DictionaryValue event;
106 event.SetInteger("id", request_id);
Nikita (slow) 2014/05/30 07:15:10 nit: You may introduce helper function that will f
mtomasz 2014/06/02 03:16:24 Done.
107 event.SetString("eventType", "destroyed");
108 event.SetDouble("time", base::Time::Now().ToJsTime());
109 web_ui()->CallJavascriptFunction("onRequestEvent", event);
110 }
111
112 void ProvidedFileSystemsWebUIHandler::OnRequestExecuted(int request_id) {
113 base::DictionaryValue event;
114 event.SetInteger("id", request_id);
115 event.SetString("eventType", "executed");
116 event.SetDouble("time", base::Time::Now().ToJsTime());
117 web_ui()->CallJavascriptFunction("onRequestEvent", event);
118 }
119
120 void ProvidedFileSystemsWebUIHandler::OnRequestFulfilled(int request_id,
121 bool has_more) {
122 base::DictionaryValue event;
123 event.SetString("eventType", "fulfilled");
124 event.SetInteger("id", request_id);
125 event.SetDouble("time", base::Time::Now().ToJsTime());
126 event.SetBoolean("hasMore", has_more);
127 web_ui()->CallJavascriptFunction("onRequestEvent", event);
128 }
129
130 void ProvidedFileSystemsWebUIHandler::OnRequestRejected(
131 int request_id,
132 base::File::Error error) {
133 base::DictionaryValue event;
134 event.SetInteger("id", request_id);
135 event.SetString("eventType", "rejected");
136 event.SetDouble("time", base::Time::Now().ToJsTime());
137 event.SetString("error", base::File::ErrorToString(error));
138
139 web_ui()->CallJavascriptFunction("onRequestEvent", event);
140 }
141
142 void ProvidedFileSystemsWebUIHandler::OnRequestTimeouted(int request_id) {
143 base::DictionaryValue event;
144 event.SetInteger("id", request_id);
145 event.SetString("eventType", "timeouted");
146 event.SetDouble("time", base::Time::Now().ToJsTime());
147 web_ui()->CallJavascriptFunction("onRequestEvent", event);
148 }
149
54 void ProvidedFileSystemsWebUIHandler::RegisterMessages() { 150 void ProvidedFileSystemsWebUIHandler::RegisterMessages() {
55 web_ui()->RegisterMessageCallback( 151 web_ui()->RegisterMessageCallback(
56 "updateFileSystems", 152 "updateFileSystems",
57 base::Bind(&ProvidedFileSystemsWebUIHandler::OnUpdateFileSystems, 153 base::Bind(&ProvidedFileSystemsWebUIHandler::UpdateFileSystems,
154 weak_ptr_factory_.GetWeakPtr()));
155 web_ui()->RegisterMessageCallback(
156 "selectFileSystem",
157 base::Bind(&ProvidedFileSystemsWebUIHandler::SelectFileSystem,
58 weak_ptr_factory_.GetWeakPtr())); 158 weak_ptr_factory_.GetWeakPtr()));
59 } 159 }
60 160
61 file_system_provider::Service* ProvidedFileSystemsWebUIHandler::GetService() { 161 file_system_provider::Service* ProvidedFileSystemsWebUIHandler::GetService() {
62 DCHECK_CURRENTLY_ON(BrowserThread::UI); 162 DCHECK_CURRENTLY_ON(BrowserThread::UI);
63 163
64 Profile* const profile = Profile::FromWebUI(web_ui()); 164 Profile* const profile = Profile::FromWebUI(web_ui());
65 return file_system_provider::ServiceFactory::FindExisting(profile); 165 return file_system_provider::ServiceFactory::FindExisting(profile);
66 } 166 }
67 167
68 void ProvidedFileSystemsWebUIHandler::OnUpdateFileSystems( 168 void ProvidedFileSystemsWebUIHandler::UpdateFileSystems(
69 const base::ListValue* args) { 169 const base::ListValue* args) {
70 DCHECK_CURRENTLY_ON(BrowserThread::UI); 170 DCHECK_CURRENTLY_ON(BrowserThread::UI);
71 171
72 file_system_provider::Service* const service = GetService(); 172 file_system_provider::Service* const service = GetService();
73 if (!service) 173 if (!service)
74 return; 174 return;
75 175
76 base::ListValue items; 176 base::ListValue items;
77 177
78 const std::vector<file_system_provider::ProvidedFileSystemInfo> 178 const std::vector<file_system_provider::ProvidedFileSystemInfo>
79 file_system_info_list = service->GetProvidedFileSystemInfoList(); 179 file_system_info_list = service->GetProvidedFileSystemInfoList();
80 180
81 for (size_t i = 0; i < file_system_info_list.size(); ++i) { 181 for (size_t i = 0; i < file_system_info_list.size(); ++i) {
82 const file_system_provider::ProvidedFileSystemInfo file_system_info = 182 const file_system_provider::ProvidedFileSystemInfo file_system_info =
83 file_system_info_list[i]; 183 file_system_info_list[i];
84 184
85 file_system_provider::ProvidedFileSystemInterface* const file_system = 185 file_system_provider::ProvidedFileSystemInterface* const file_system =
86 service->GetProvidedFileSystem(file_system_info.extension_id(), 186 service->GetProvidedFileSystem(file_system_info.extension_id(),
87 file_system_info.file_system_id()); 187 file_system_info.file_system_id());
88 DCHECK(file_system); 188 DCHECK(file_system);
89 189
90 file_system_provider::RequestManager* const request_manager = 190 file_system_provider::RequestManager* const request_manager =
91 file_system->GetRequestManager(); 191 file_system->GetRequestManager();
92 DCHECK(request_manager); 192 DCHECK(request_manager);
93 193
94 base::DictionaryValue* item_value = new base::DictionaryValue(); 194 base::DictionaryValue* item = new base::DictionaryValue();
95 item_value->SetString("id", file_system_info.file_system_id()); 195 item->SetString("id", file_system_info.file_system_id());
96 item_value->SetString("name", file_system_info.file_system_name()); 196 item->SetString("name", file_system_info.file_system_name());
97 item_value->SetString("extensionId", file_system_info.extension_id()); 197 item->SetString("extensionId", file_system_info.extension_id());
98 item_value->SetString("mountPath", 198 item->SetString("mountPath", file_system_info.mount_path().AsUTF8Unsafe());
99 file_system_info.mount_path().AsUTF8Unsafe()); 199 item->SetInteger("activeRequests",
100 item_value->SetInteger("activeRequests", 200 request_manager->GetActiveRequestsForLogging());
101 request_manager->GetActiveRequestsForLogging());
102 201
103 items.Append(item_value); 202 items.Append(item);
104 } 203 }
105 204
106 web_ui()->CallJavascriptFunction("updateFileSystems", items); 205 web_ui()->CallJavascriptFunction("updateFileSystems", items);
107 } 206 }
108 207
208 void ProvidedFileSystemsWebUIHandler::SelectFileSystem(
209 const base::ListValue* args) {
210 DCHECK_CURRENTLY_ON(BrowserThread::UI);
211
212 file_system_provider::Service* const service = GetService();
213 if (!service)
214 return;
215
216 std::string extension_id;
217 if (!args->GetString(0, &extension_id))
218 return;
219
220 std::string file_system_id;
221 if (!args->GetString(1, &file_system_id))
222 return;
223
224 // Stop observing the previously selected request manager.
225 {
226 file_system_provider::ProvidedFileSystemInterface* const file_system =
227 service->GetProvidedFileSystem(selected_extension_id,
228 selected_file_system_id);
229 if (file_system) {
230 file_system_provider::RequestManager* const request_manager =
Nikita (slow) 2014/05/30 07:15:10 nit: file_system->GetRequestManager()->RemoveObser
mtomasz 2014/06/02 03:16:24 As above.
231 file_system->GetRequestManager();
232 DCHECK(request_manager);
233 request_manager->RemoveObserver(this);
234 }
235 }
236
237 // Observe the selected file system.
238 file_system_provider::ProvidedFileSystemInterface* const file_system =
239 service->GetProvidedFileSystem(extension_id, file_system_id);
240 if (!file_system)
241 return;
242
243 file_system_provider::RequestManager* const request_manager =
Nikita (slow) 2014/05/30 07:15:10 nit: same here.
mtomasz 2014/06/02 03:16:24 As above.
244 file_system->GetRequestManager();
245 DCHECK(request_manager);
246
247 request_manager->AddObserver(this);
248 selected_extension_id = extension_id;
249 selected_file_system_id = file_system_id;
250 }
251
109 } // namespace 252 } // namespace
110 253
111 ProvidedFileSystemsUI::ProvidedFileSystemsUI(content::WebUI* web_ui) 254 ProvidedFileSystemsUI::ProvidedFileSystemsUI(content::WebUI* web_ui)
112 : WebUIController(web_ui) { 255 : WebUIController(web_ui) {
113 web_ui->AddMessageHandler(new ProvidedFileSystemsWebUIHandler()); 256 web_ui->AddMessageHandler(new ProvidedFileSystemsWebUIHandler());
114 257
115 content::WebUIDataSource* source = content::WebUIDataSource::Create( 258 content::WebUIDataSource* source = content::WebUIDataSource::Create(
116 chrome::kChromeUIProvidedFileSystemsHost); 259 chrome::kChromeUIProvidedFileSystemsHost);
117 source->AddResourcePath("provided_file_systems.css", 260 source->AddResourcePath("provided_file_systems.css",
118 IDR_PROVIDED_FILE_SYSTEMS_CSS); 261 IDR_PROVIDED_FILE_SYSTEMS_CSS);
119 source->AddResourcePath("provided_file_systems.js", 262 source->AddResourcePath("provided_file_systems.js",
120 IDR_PROVIDED_FILE_SYSTEMS_JS); 263 IDR_PROVIDED_FILE_SYSTEMS_JS);
121 source->SetDefaultResource(IDR_PROVIDED_FILE_SYSTEMS_HTML); 264 source->SetDefaultResource(IDR_PROVIDED_FILE_SYSTEMS_HTML);
122 265
123 Profile* profile = Profile::FromWebUI(web_ui); 266 Profile* profile = Profile::FromWebUI(web_ui);
124 content::WebUIDataSource::Add(profile, source); 267 content::WebUIDataSource::Add(profile, source);
125 } 268 }
126 269
127 } // namespace chromeos 270 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/resources/chromeos/provided_file_systems.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698