OLD | NEW |
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/fsp_internals_ui.h" | 5 #include "chrome/browser/ui/webui/chromeos/provided_file_systems_ui.h" |
| 6 |
| 7 #include <vector> |
6 | 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
9 #include "base/values.h" | 11 #include "base/values.h" |
10 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info
.h" | 12 #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" | 13 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte
rface.h" |
12 #include "chrome/browser/chromeos/file_system_provider/request_manager.h" | 14 #include "chrome/browser/chromeos/file_system_provider/request_manager.h" |
13 #include "chrome/browser/chromeos/file_system_provider/service.h" | 15 #include "chrome/browser/chromeos/file_system_provider/service.h" |
14 #include "chrome/browser/chromeos/file_system_provider/service_factory.h" | 16 #include "chrome/browser/chromeos/file_system_provider/service_factory.h" |
15 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/common/url_constants.h" | 18 #include "chrome/common/url_constants.h" |
17 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
18 #include "content/public/browser/web_ui.h" | 20 #include "content/public/browser/web_ui.h" |
19 #include "content/public/browser/web_ui_data_source.h" | 21 #include "content/public/browser/web_ui_data_source.h" |
20 #include "content/public/browser/web_ui_message_handler.h" | 22 #include "content/public/browser/web_ui_message_handler.h" |
21 #include "grit/browser_resources.h" | 23 #include "grit/browser_resources.h" |
22 | 24 |
23 using content::BrowserThread; | 25 using content::BrowserThread; |
24 | 26 |
25 namespace chromeos { | 27 namespace chromeos { |
26 | 28 |
27 namespace { | 29 namespace { |
28 | 30 |
29 // Class to handle messages from chrome://fsp-internals. | 31 // Class to handle messages from chrome://provided-file-systems. |
30 class FSPInternalsWebUIHandler : public content::WebUIMessageHandler { | 32 class ProvidedFileSystemsWebUIHandler : public content::WebUIMessageHandler { |
31 public: | 33 public: |
32 FSPInternalsWebUIHandler() : weak_ptr_factory_(this) {} | 34 ProvidedFileSystemsWebUIHandler() : weak_ptr_factory_(this) {} |
33 | 35 |
34 virtual ~FSPInternalsWebUIHandler() {} | 36 virtual ~ProvidedFileSystemsWebUIHandler() {} |
35 | 37 |
36 private: | 38 private: |
37 // content::WebUIMessageHandler overrides. | 39 // content::WebUIMessageHandler overrides. |
38 virtual void RegisterMessages() OVERRIDE; | 40 virtual void RegisterMessages() OVERRIDE; |
39 | 41 |
40 // Gets a file system provider service for the current profile. If not found, | 42 // Gets a file system provider service for the current profile. If not found, |
41 // then NULL. | 43 // then NULL. |
42 file_system_provider::Service* GetService(); | 44 file_system_provider::Service* GetService(); |
43 | 45 |
44 // Invoked when updating file system list is requested. | 46 // Invoked when updating file system list is requested. |
45 void OnUpdateFileSystems(const base::ListValue* args); | 47 void OnUpdateFileSystems(const base::ListValue* args); |
46 | 48 |
47 base::WeakPtrFactory<FSPInternalsWebUIHandler> weak_ptr_factory_; | 49 base::WeakPtrFactory<ProvidedFileSystemsWebUIHandler> weak_ptr_factory_; |
48 | 50 |
49 DISALLOW_COPY_AND_ASSIGN(FSPInternalsWebUIHandler); | 51 DISALLOW_COPY_AND_ASSIGN(ProvidedFileSystemsWebUIHandler); |
50 }; | 52 }; |
51 | 53 |
52 void FSPInternalsWebUIHandler::RegisterMessages() { | 54 void ProvidedFileSystemsWebUIHandler::RegisterMessages() { |
53 web_ui()->RegisterMessageCallback( | 55 web_ui()->RegisterMessageCallback( |
54 "updateFileSystems", | 56 "updateFileSystems", |
55 base::Bind(&FSPInternalsWebUIHandler::OnUpdateFileSystems, | 57 base::Bind(&ProvidedFileSystemsWebUIHandler::OnUpdateFileSystems, |
56 weak_ptr_factory_.GetWeakPtr())); | 58 weak_ptr_factory_.GetWeakPtr())); |
57 } | 59 } |
58 | 60 |
59 file_system_provider::Service* FSPInternalsWebUIHandler::GetService() { | 61 file_system_provider::Service* ProvidedFileSystemsWebUIHandler::GetService() { |
60 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 62 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
61 | 63 |
62 Profile* const profile = Profile::FromWebUI(web_ui()); | 64 Profile* const profile = Profile::FromWebUI(web_ui()); |
63 return file_system_provider::ServiceFactory::FindExisting(profile); | 65 return file_system_provider::ServiceFactory::FindExisting(profile); |
64 } | 66 } |
65 | 67 |
66 void FSPInternalsWebUIHandler::OnUpdateFileSystems( | 68 void ProvidedFileSystemsWebUIHandler::OnUpdateFileSystems( |
67 const base::ListValue* args) { | 69 const base::ListValue* args) { |
68 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 70 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
69 | 71 |
70 file_system_provider::Service* const service = GetService(); | 72 file_system_provider::Service* const service = GetService(); |
71 if (!service) | 73 if (!service) |
72 return; | 74 return; |
73 | 75 |
74 base::ListValue items; | 76 base::ListValue items; |
75 | 77 |
76 const std::vector<file_system_provider::ProvidedFileSystemInfo> | 78 const std::vector<file_system_provider::ProvidedFileSystemInfo> |
(...skipping 22 matching lines...) Expand all Loading... |
99 request_manager->GetActiveRequestsForLogging()); | 101 request_manager->GetActiveRequestsForLogging()); |
100 | 102 |
101 items.Append(item_value); | 103 items.Append(item_value); |
102 } | 104 } |
103 | 105 |
104 web_ui()->CallJavascriptFunction("updateFileSystems", items); | 106 web_ui()->CallJavascriptFunction("updateFileSystems", items); |
105 } | 107 } |
106 | 108 |
107 } // namespace | 109 } // namespace |
108 | 110 |
109 FSPInternalsUI::FSPInternalsUI(content::WebUI* web_ui) | 111 ProvidedFileSystemsUI::ProvidedFileSystemsUI(content::WebUI* web_ui) |
110 : WebUIController(web_ui) { | 112 : WebUIController(web_ui) { |
111 web_ui->AddMessageHandler(new FSPInternalsWebUIHandler()); | 113 web_ui->AddMessageHandler(new ProvidedFileSystemsWebUIHandler()); |
112 | 114 |
113 content::WebUIDataSource* source = | 115 content::WebUIDataSource* source = content::WebUIDataSource::Create( |
114 content::WebUIDataSource::Create(chrome::kChromeUIFSPInternalsHost); | 116 chrome::kChromeUIProvidedFileSystemsHost); |
115 source->AddResourcePath("fsp_internals.css", IDR_FSP_INTERNALS_CSS); | 117 source->AddResourcePath("provided_file_systems.css", |
116 source->AddResourcePath("fsp_internals.js", IDR_FSP_INTERNALS_JS); | 118 IDR_PROVIDED_FILE_SYSTEMS_CSS); |
117 source->SetDefaultResource(IDR_FSP_INTERNALS_HTML); | 119 source->AddResourcePath("provided_file_systems.js", |
| 120 IDR_PROVIDED_FILE_SYSTEMS_JS); |
| 121 source->SetDefaultResource(IDR_PROVIDED_FILE_SYSTEMS_HTML); |
118 | 122 |
119 Profile* profile = Profile::FromWebUI(web_ui); | 123 Profile* profile = Profile::FromWebUI(web_ui); |
120 content::WebUIDataSource::Add(profile, source); | 124 content::WebUIDataSource::Add(profile, source); |
121 } | 125 } |
122 | 126 |
123 } // namespace chromeos | 127 } // namespace chromeos |
OLD | NEW |