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

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

Issue 9019002: [CrosDisksClient] Determine device type from DeviceMediaType property sent by cros-disks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: little error in imageburner Created 8 years, 11 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/imageburner/imageburner_ui.h" 5 #include "chrome/browser/ui/webui/chromeos/imageburner/imageburner_ui.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 12 matching lines...) Expand all
23 #include "content/browser/webui/web_ui.h" 23 #include "content/browser/webui/web_ui.h"
24 #include "content/public/browser/browser_thread.h" 24 #include "content/public/browser/browser_thread.h"
25 #include "content/public/browser/web_contents.h" 25 #include "content/public/browser/web_contents.h"
26 #include "grit/browser_resources.h" 26 #include "grit/browser_resources.h"
27 #include "grit/generated_resources.h" 27 #include "grit/generated_resources.h"
28 #include "grit/locale_settings.h" 28 #include "grit/locale_settings.h"
29 #include "ui/base/l10n/l10n_util.h" 29 #include "ui/base/l10n/l10n_util.h"
30 #include "ui/base/resource/resource_bundle.h" 30 #include "ui/base/resource/resource_bundle.h"
31 #include "ui/base/text/bytes_formatting.h" 31 #include "ui/base/text/bytes_formatting.h"
32 32
33 using chromeos::disks::DiskMountManager;
34 using chromeos::disks::DiskMountManagerEventType;
33 using content::BrowserThread; 35 using content::BrowserThread;
34 using content::DownloadItem; 36 using content::DownloadItem;
35 using content::WebContents; 37 using content::WebContents;
36 38
39 namespace {
40
37 const char kPropertyDevicePath[] = "devicePath"; 41 const char kPropertyDevicePath[] = "devicePath";
38 const char kPropertyFilePath[] = "filePath"; 42 const char kPropertyFilePath[] = "filePath";
39 const char kPropertyLabel[] = "label"; 43 const char kPropertyLabel[] = "label";
40 const char kPropertyPath[] = "path"; 44 const char kPropertyPath[] = "path";
45 const char kPropertyDeviceType[] = "type";
41 46
42 // Name for hwid in machine statistics. 47 // Name for hwid in machine statistics.
43 const char kHwidStatistic[] = "hardware_class"; 48 const char kHwidStatistic[] = "hardware_class";
44 49
45 const char kImageZipFileName[] = "chromeos_image.bin.zip"; 50 const char kImageZipFileName[] = "chromeos_image.bin.zip";
46 51
47 // 3.9GB. It is less than 4GB because true device size ussually varies a little. 52 // 3.9GB. It is less than 4GB because true device size ussually varies a little.
48 const uint64 kMinDeviceSize = static_cast<uint64>(3.9) * 1000 * 1000 * 1000; 53 const uint64 kMinDeviceSize = static_cast<uint64>(3.9) * 1000 * 1000 * 1000;
49 54
50 // Link displayed on imageburner ui. 55 // Link displayed on imageburner ui.
51 const char kMoreInfoLink[] = 56 const char kMoreInfoLink[] =
52 "http://www.chromium.org/chromium-os/chromiumos-design-docs/recovery-mode"; 57 "http://www.chromium.org/chromium-os/chromiumos-design-docs/recovery-mode";
53 58
54 namespace { 59 bool AllowBurnToDevice(const DiskMountManager::Disk* disk) {
achuithb 2012/01/23 22:17:17 might be nicer to use const DiskMountManager::Disk
tbarzic 2012/01/23 22:42:40 Done.
60 return disk->is_parent() && !disk->on_boot_device() &&
61 (disk->device_type() == chromeos::DEVICE_TYPE_USB ||
62 disk->device_type() == chromeos::DEVICE_TYPE_SD);
63 }
55 64
56 ChromeWebUIDataSource* CreateImageburnerUIHTMLSource() { 65 ChromeWebUIDataSource* CreateImageburnerUIHTMLSource() {
57 ChromeWebUIDataSource* source = 66 ChromeWebUIDataSource* source =
58 new ChromeWebUIDataSource(chrome::kChromeUIImageBurnerHost); 67 new ChromeWebUIDataSource(chrome::kChromeUIImageBurnerHost);
59 68
60 source->AddLocalizedString("headerTitle", IDS_IMAGEBURN_HEADER_TITLE); 69 source->AddLocalizedString("headerTitle", IDS_IMAGEBURN_HEADER_TITLE);
61 source->AddLocalizedString("headerDescription", 70 source->AddLocalizedString("headerDescription",
62 IDS_IMAGEBURN_HEADER_DESCRIPTION); 71 IDS_IMAGEBURN_HEADER_DESCRIPTION);
63 source->AddLocalizedString("headerLink", IDS_IMAGEBURN_HEADER_LINK); 72 source->AddLocalizedString("headerLink", IDS_IMAGEBURN_HEADER_LINK);
64 source->AddLocalizedString("statusDevicesNone", 73 source->AddLocalizedString("statusDevicesNone",
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 //////////////////////////////////////////////////////////////////////////////// 139 ////////////////////////////////////////////////////////////////////////////////
131 140
132 WebUIHandler::WebUIHandler(WebContents* contents) 141 WebUIHandler::WebUIHandler(WebContents* contents)
133 : web_contents_(contents), 142 : web_contents_(contents),
134 download_manager_(NULL), 143 download_manager_(NULL),
135 active_download_item_(NULL), 144 active_download_item_(NULL),
136 burn_manager_(NULL), 145 burn_manager_(NULL),
137 state_machine_(NULL), 146 state_machine_(NULL),
138 observing_burn_lib_(false), 147 observing_burn_lib_(false),
139 working_(false) { 148 working_(false) {
140 chromeos::disks::DiskMountManager::GetInstance()->AddObserver(this); 149 DiskMountManager::GetInstance()->AddObserver(this);
141 chromeos::CrosLibrary::Get()->GetNetworkLibrary()-> 150 chromeos::CrosLibrary::Get()->GetNetworkLibrary()->
142 AddNetworkManagerObserver(this); 151 AddNetworkManagerObserver(this);
143 burn_manager_ = BurnManager::GetInstance(); 152 burn_manager_ = BurnManager::GetInstance();
144 state_machine_ = burn_manager_->state_machine(); 153 state_machine_ = burn_manager_->state_machine();
145 state_machine_->AddObserver(this); 154 state_machine_->AddObserver(this);
146 } 155 }
147 156
148 WebUIHandler::~WebUIHandler() { 157 WebUIHandler::~WebUIHandler() {
149 chromeos::disks::DiskMountManager::GetInstance()-> 158 DiskMountManager::GetInstance()->RemoveObserver(this);
150 RemoveObserver(this);
151 chromeos::CrosLibrary::Get()->GetBurnLibrary()->RemoveObserver(this); 159 chromeos::CrosLibrary::Get()->GetBurnLibrary()->RemoveObserver(this);
152 chromeos::CrosLibrary::Get()->GetNetworkLibrary()-> 160 chromeos::CrosLibrary::Get()->GetNetworkLibrary()->
153 RemoveNetworkManagerObserver(this); 161 RemoveNetworkManagerObserver(this);
154 CleanupDownloadObjects(); 162 CleanupDownloadObjects();
155 if (state_machine_) 163 if (state_machine_)
156 state_machine_->RemoveObserver(this); 164 state_machine_->RemoveObserver(this);
157 } 165 }
158 166
159 void WebUIHandler::RegisterMessages() { 167 void WebUIHandler::RegisterMessages() {
160 web_ui()->RegisterMessageCallback("getDevices", 168 web_ui()->RegisterMessageCallback("getDevices",
161 base::Bind(&WebUIHandler::HandleGetDevices, base::Unretained(this))); 169 base::Bind(&WebUIHandler::HandleGetDevices, base::Unretained(this)));
162 web_ui()->RegisterMessageCallback("burnImage", 170 web_ui()->RegisterMessageCallback("burnImage",
163 base::Bind(&WebUIHandler::HandleBurnImage, base::Unretained(this))); 171 base::Bind(&WebUIHandler::HandleBurnImage, base::Unretained(this)));
164 web_ui()->RegisterMessageCallback("cancelBurnImage", 172 web_ui()->RegisterMessageCallback("cancelBurnImage",
165 base::Bind(&WebUIHandler::HandleCancelBurnImage, base::Unretained(this))); 173 base::Bind(&WebUIHandler::HandleCancelBurnImage, base::Unretained(this)));
166 web_ui()->RegisterMessageCallback("webuiInitialized", 174 web_ui()->RegisterMessageCallback("webuiInitialized",
167 base::Bind(&WebUIHandler::HandleWebUIInitialized, 175 base::Bind(&WebUIHandler::HandleWebUIInitialized,
168 base::Unretained(this))); 176 base::Unretained(this)));
169 } 177 }
170 178
171 void WebUIHandler::DiskChanged( 179 void WebUIHandler::DiskChanged(DiskMountManagerEventType event,
172 chromeos::disks::DiskMountManagerEventType event, 180 const DiskMountManager::Disk* disk) {
achuithb 2012/01/23 22:17:17 Disk&?
tbarzic 2012/01/23 22:42:40 This is DiskMountManager observer method, so I wou
173 const chromeos::disks::DiskMountManager::Disk* disk) { 181 if (!AllowBurnToDevice(disk))
174 if (!disk->is_parent() || disk->on_boot_device())
175 return; 182 return;
176 if (event == chromeos::disks::MOUNT_DISK_ADDED) { 183 if (event == chromeos::disks::MOUNT_DISK_ADDED) {
177 DictionaryValue disk_value; 184 DictionaryValue disk_value;
178 CreateDiskValue(*disk, &disk_value); 185 CreateDiskValue(*disk, &disk_value);
179 web_ui()->CallJavascriptFunction("browserBridge.deviceAdded", disk_value); 186 web_ui()->CallJavascriptFunction("browserBridge.deviceAdded", disk_value);
180 } else if (event == chromeos::disks::MOUNT_DISK_REMOVED) { 187 } else if (event == chromeos::disks::MOUNT_DISK_REMOVED) {
181 StringValue device_path_value(disk->device_path()); 188 StringValue device_path_value(disk->device_path());
182 web_ui()->CallJavascriptFunction("browserBridge.deviceRemoved", 189 web_ui()->CallJavascriptFunction("browserBridge.deviceRemoved",
183 device_path_value); 190 device_path_value);
184 if (burn_manager_->target_device_path().value() == 191 if (burn_manager_->target_device_path().value() ==
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 HandleBurnImage(NULL); 287 HandleBurnImage(NULL);
281 } 288 }
282 } 289 }
283 290
284 void WebUIHandler::OnError(int error_message_id) { 291 void WebUIHandler::OnError(int error_message_id) {
285 StringValue error_message(l10n_util::GetStringUTF16(error_message_id)); 292 StringValue error_message(l10n_util::GetStringUTF16(error_message_id));
286 web_ui()->CallJavascriptFunction("browserBridge.reportFail", error_message); 293 web_ui()->CallJavascriptFunction("browserBridge.reportFail", error_message);
287 working_ = false; 294 working_ = false;
288 } 295 }
289 296
290 void WebUIHandler::CreateDiskValue( 297 void WebUIHandler::CreateDiskValue(const DiskMountManager::Disk& disk,
291 const chromeos::disks::DiskMountManager::Disk& disk, 298 DictionaryValue* disk_value) {
292 DictionaryValue* disk_value) {
293 string16 label = ASCIIToUTF16(disk.drive_label()); 299 string16 label = ASCIIToUTF16(disk.drive_label());
294 base::i18n::AdjustStringForLocaleDirection(&label); 300 base::i18n::AdjustStringForLocaleDirection(&label);
295 disk_value->SetString(std::string(kPropertyLabel), label); 301 disk_value->SetString(std::string(kPropertyLabel), label);
296 disk_value->SetString(std::string(kPropertyFilePath), disk.file_path()); 302 disk_value->SetString(std::string(kPropertyFilePath), disk.file_path());
297 disk_value->SetString(std::string(kPropertyDevicePath), disk.device_path()); 303 disk_value->SetString(std::string(kPropertyDevicePath), disk.device_path());
304 disk_value->SetString(std::string(kPropertyDeviceType),
305 DiskMountManager::DeviceTypeToString(disk.device_type()));
298 } 306 }
299 307
300 void WebUIHandler::HandleGetDevices(const ListValue* args) { 308 void WebUIHandler::HandleGetDevices(const ListValue* args) {
301 chromeos::disks::DiskMountManager* disk_mount_manager = 309 DiskMountManager* disk_mount_manager = DiskMountManager::GetInstance();
302 chromeos::disks::DiskMountManager::GetInstance(); 310 const DiskMountManager::DiskMap& disks = disk_mount_manager->disks();
303 const chromeos::disks::DiskMountManager::DiskMap& disks =
304 disk_mount_manager->disks();
305 ListValue results_value; 311 ListValue results_value;
306 for (chromeos::disks::DiskMountManager::DiskMap::const_iterator iter = 312 for (DiskMountManager::DiskMap::const_iterator iter = disks.begin();
307 disks.begin();
308 iter != disks.end(); 313 iter != disks.end();
309 ++iter) { 314 ++iter) {
310 chromeos::disks::DiskMountManager::Disk* disk = iter->second; 315 DiskMountManager::Disk* disk = iter->second;
311 if (disk->is_parent() && !disk->on_boot_device()) { 316 if (AllowBurnToDevice(disk)) {
312 DictionaryValue* disk_value = new DictionaryValue(); 317 DictionaryValue* disk_value = new DictionaryValue();
313 CreateDiskValue(*disk, disk_value); 318 CreateDiskValue(*disk, disk_value);
314 results_value.Append(disk_value); 319 results_value.Append(disk_value);
315 } 320 }
316 } 321 }
317 web_ui()->CallJavascriptFunction("browserBridge.getDevicesCallback", 322 web_ui()->CallJavascriptFunction("browserBridge.getDevicesCallback",
318 results_value); 323 results_value);
319 } 324 }
320 325
321 void WebUIHandler::HandleWebUIInitialized(const ListValue* args) { 326 void WebUIHandler::HandleWebUIInitialized(const ListValue* args) {
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 std::string image_dest; 624 std::string image_dest;
620 string_value->GetAsString(&image_dest); 625 string_value->GetAsString(&image_dest);
621 *device_path = FilePath(image_dest); 626 *device_path = FilePath(image_dest);
622 } else { 627 } else {
623 LOG(ERROR) << "Unable to get path string"; 628 LOG(ERROR) << "Unable to get path string";
624 device_path->clear(); 629 device_path->clear();
625 } 630 }
626 } 631 }
627 632
628 int64 WebUIHandler::GetDeviceSize(const std::string& device_path) { 633 int64 WebUIHandler::GetDeviceSize(const std::string& device_path) {
629 chromeos::disks::DiskMountManager* disk_mount_manager = 634 DiskMountManager* disk_mount_manager = DiskMountManager::GetInstance();
630 chromeos::disks::DiskMountManager::GetInstance(); 635 const DiskMountManager::DiskMap& disks = disk_mount_manager->disks();
631 const chromeos::disks::DiskMountManager::DiskMap& disks =
632 disk_mount_manager->disks();
633 return disks.find(device_path)->second->total_size_in_bytes(); 636 return disks.find(device_path)->second->total_size_in_bytes();
634 } 637 }
635 638
636 bool WebUIHandler::CheckNetwork() { 639 bool WebUIHandler::CheckNetwork() {
637 return chromeos::CrosLibrary::Get()->GetNetworkLibrary()->Connected(); 640 return chromeos::CrosLibrary::Get()->GetNetworkLibrary()->Connected();
638 } 641 }
639 642
640 } // namespace imageburner. 643 } // namespace imageburner.
641 644
642 //////////////////////////////////////////////////////////////////////////////// 645 ////////////////////////////////////////////////////////////////////////////////
643 // 646 //
644 // ImageBurnUI 647 // ImageBurnUI
645 // 648 //
646 //////////////////////////////////////////////////////////////////////////////// 649 ////////////////////////////////////////////////////////////////////////////////
647 650
648 ImageBurnUI::ImageBurnUI(WebContents* contents) : WebUI(contents) { 651 ImageBurnUI::ImageBurnUI(WebContents* contents) : WebUI(contents) {
649 imageburner::WebUIHandler* handler = new imageburner::WebUIHandler(contents); 652 imageburner::WebUIHandler* handler = new imageburner::WebUIHandler(contents);
650 AddMessageHandler(handler); 653 AddMessageHandler(handler);
651 654
652 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); 655 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
653 profile->GetChromeURLDataManager()->AddDataSource( 656 profile->GetChromeURLDataManager()->AddDataSource(
654 CreateImageburnerUIHTMLSource()); 657 CreateImageburnerUIHTMLSource());
655 } 658 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698