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

Side by Side Diff: chrome/browser/storage_monitor/storage_monitor_win.cc

Issue 12382005: Rename RemovableDeviceNotifications=>StorageMonitor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix some includes from recent merge. Created 7 years, 9 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
OLDNEW
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/storage_monitor/removable_device_notifications_window_w in.h" 5 #include "chrome/browser/storage_monitor/storage_monitor_win.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <dbt.h> 8 #include <dbt.h>
9 #include <fileapi.h> 9 #include <fileapi.h>
10 10
11 #include "base/win/wrapped_window_proc.h" 11 #include "base/win/wrapped_window_proc.h"
12 #include "chrome/browser/storage_monitor/media_storage_util.h" 12 #include "chrome/browser/storage_monitor/media_storage_util.h"
13 #include "chrome/browser/storage_monitor/portable_device_watcher_win.h" 13 #include "chrome/browser/storage_monitor/portable_device_watcher_win.h"
14 #include "chrome/browser/storage_monitor/removable_device_constants.h" 14 #include "chrome/browser/storage_monitor/removable_device_constants.h"
15 #include "chrome/browser/storage_monitor/volume_mount_watcher_win.h" 15 #include "chrome/browser/storage_monitor/volume_mount_watcher_win.h"
16 16
17 namespace chrome { 17 namespace chrome {
18 18
19 namespace { 19 namespace {
20 20
21 const char16 kWindowClassName[] = L"Chrome_RemovableDeviceNotificationWindow"; 21 const char16 kWindowClassName[] = L"Chrome_RemovableDeviceNotificationWindow";
22 22
23 } // namespace 23 } // namespace
24 24
25 25
26 // RemovableDeviceNotificationsWindowWin -------------------------------------- 26 // StorageMonitorWindowWin --------------------------------------
27 27
28 // static 28 // static
29 RemovableDeviceNotificationsWindowWin* 29 StorageMonitorWin*
30 RemovableDeviceNotificationsWindowWin::Create() { 30 StorageMonitorWin::Create() {
vandebo (ex-Chrome) 2013/03/01 19:47:39 nit: line wrap.
31 return new RemovableDeviceNotificationsWindowWin( 31 return new StorageMonitorWin(
32 new VolumeMountWatcherWin(), new PortableDeviceWatcherWin()); 32 new VolumeMountWatcherWin(), new PortableDeviceWatcherWin());
vandebo (ex-Chrome) 2013/03/01 19:47:39 nit: line wrap.
33 } 33 }
34 34
35 RemovableDeviceNotificationsWindowWin:: 35 StorageMonitorWin::
36 RemovableDeviceNotificationsWindowWin( 36 StorageMonitorWin(
vandebo (ex-Chrome) 2013/03/01 19:47:39 nit: line wrap.
37 VolumeMountWatcherWin* volume_mount_watcher, 37 VolumeMountWatcherWin* volume_mount_watcher,
38 PortableDeviceWatcherWin* portable_device_watcher) 38 PortableDeviceWatcherWin* portable_device_watcher)
39 : window_class_(0), 39 : window_class_(0),
40 instance_(NULL), 40 instance_(NULL),
41 window_(NULL), 41 window_(NULL),
42 volume_mount_watcher_(volume_mount_watcher), 42 volume_mount_watcher_(volume_mount_watcher),
43 portable_device_watcher_(portable_device_watcher) { 43 portable_device_watcher_(portable_device_watcher) {
44 DCHECK(volume_mount_watcher_); 44 DCHECK(volume_mount_watcher_);
45 DCHECK(portable_device_watcher_); 45 DCHECK(portable_device_watcher_);
46 volume_mount_watcher_->SetNotifications(receiver()); 46 volume_mount_watcher_->SetNotifications(receiver());
47 portable_device_watcher_->SetNotifications(receiver()); 47 portable_device_watcher_->SetNotifications(receiver());
48 } 48 }
49 49
50 RemovableDeviceNotificationsWindowWin:: 50 StorageMonitorWin::
51 ~RemovableDeviceNotificationsWindowWin() { 51 ~StorageMonitorWin() {
vandebo (ex-Chrome) 2013/03/01 19:47:39 nit: line warp.
52 volume_mount_watcher_->SetNotifications(NULL); 52 volume_mount_watcher_->SetNotifications(NULL);
53 portable_device_watcher_->SetNotifications(NULL); 53 portable_device_watcher_->SetNotifications(NULL);
54 54
55 if (window_) 55 if (window_)
56 DestroyWindow(window_); 56 DestroyWindow(window_);
57 57
58 if (window_class_) 58 if (window_class_)
59 UnregisterClass(MAKEINTATOM(window_class_), instance_); 59 UnregisterClass(MAKEINTATOM(window_class_), instance_);
60 } 60 }
61 61
62 void RemovableDeviceNotificationsWindowWin::Init() { 62 void StorageMonitorWin::Init() {
63 WNDCLASSEX window_class; 63 WNDCLASSEX window_class;
64 base::win::InitializeWindowClass( 64 base::win::InitializeWindowClass(
65 kWindowClassName, 65 kWindowClassName,
66 &base::win::WrappedWindowProc< 66 &base::win::WrappedWindowProc<
67 RemovableDeviceNotificationsWindowWin::WndProcThunk>, 67 StorageMonitorWin::WndProcThunk>,
vandebo (ex-Chrome) 2013/03/01 19:47:39 nit: line wrap.
68 0, 0, 0, NULL, NULL, NULL, NULL, NULL, 68 0, 0, 0, NULL, NULL, NULL, NULL, NULL,
69 &window_class); 69 &window_class);
70 instance_ = window_class.hInstance; 70 instance_ = window_class.hInstance;
71 window_class_ = RegisterClassEx(&window_class); 71 window_class_ = RegisterClassEx(&window_class);
72 DCHECK(window_class_); 72 DCHECK(window_class_);
73 73
74 window_ = CreateWindow(MAKEINTATOM(window_class_), 0, 0, 0, 0, 0, 0, 0, 0, 74 window_ = CreateWindow(MAKEINTATOM(window_class_), 0, 0, 0, 0, 0, 0, 0, 0,
75 instance_, 0); 75 instance_, 0);
76 SetWindowLongPtr(window_, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this)); 76 SetWindowLongPtr(window_, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));
77 volume_mount_watcher_->Init(); 77 volume_mount_watcher_->Init();
78 portable_device_watcher_->Init(window_); 78 portable_device_watcher_->Init(window_);
79 } 79 }
80 80
81 bool RemovableDeviceNotificationsWindowWin::GetStorageInfoForPath( 81 bool StorageMonitorWin::GetStorageInfoForPath(
82 const base::FilePath& path, 82 const base::FilePath& path,
83 StorageInfo* device_info) const { 83 StorageInfo* device_info) const {
vandebo (ex-Chrome) 2013/03/01 19:47:39 nit: line wrap.
84 string16 location; 84 string16 location;
85 std::string unique_id; 85 std::string unique_id;
86 string16 name; 86 string16 name;
87 bool removable; 87 bool removable;
88 uint64 total_size_in_bytes; 88 uint64 total_size_in_bytes;
89 if (!GetDeviceInfo(path, &location, &unique_id, &name, &removable, 89 if (!GetDeviceInfo(path, &location, &unique_id, &name, &removable,
90 &total_size_in_bytes)) { 90 &total_size_in_bytes)) {
91 return false; 91 return false;
92 } 92 }
93 93
(...skipping 24 matching lines...) Expand all
118 } 118 }
119 119
120 if (device_info) { 120 if (device_info) {
121 device_info->device_id = device_id; 121 device_info->device_id = device_id;
122 device_info->name = name; 122 device_info->name = name;
123 device_info->location = location; 123 device_info->location = location;
124 } 124 }
125 return true; 125 return true;
126 } 126 }
127 127
128 uint64 RemovableDeviceNotificationsWindowWin::GetStorageSize( 128 uint64 StorageMonitorWin::GetStorageSize(
129 const base::FilePath::StringType& location) const { 129 const base::FilePath::StringType& location) const {
130 return volume_mount_watcher_->GetStorageSize(location); 130 return volume_mount_watcher_->GetStorageSize(location);
131 } 131 }
132 132
133 bool RemovableDeviceNotificationsWindowWin::GetMTPStorageInfoFromDeviceId( 133 bool StorageMonitorWin::GetMTPStorageInfoFromDeviceId(
134 const std::string& storage_device_id, 134 const std::string& storage_device_id,
135 string16* device_location, 135 string16* device_location,
136 string16* storage_object_id) const { 136 string16* storage_object_id) const {
137 MediaStorageUtil::Type type; 137 MediaStorageUtil::Type type;
138 MediaStorageUtil::CrackDeviceId(storage_device_id, &type, NULL); 138 MediaStorageUtil::CrackDeviceId(storage_device_id, &type, NULL);
139 return ((type == MediaStorageUtil::MTP_OR_PTP) && 139 return ((type == MediaStorageUtil::MTP_OR_PTP) &&
140 portable_device_watcher_->GetMTPStorageInfoFromDeviceId( 140 portable_device_watcher_->GetMTPStorageInfoFromDeviceId(
141 storage_device_id, device_location, storage_object_id)); 141 storage_device_id, device_location, storage_object_id));
142 } 142 }
143 143
144 // static 144 // static
145 LRESULT CALLBACK RemovableDeviceNotificationsWindowWin::WndProcThunk( 145 LRESULT CALLBACK StorageMonitorWin::WndProcThunk(
146 HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) { 146 HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) {
vandebo (ex-Chrome) 2013/03/01 19:47:39 nit: line wrap.
147 RemovableDeviceNotificationsWindowWin* msg_wnd = 147 StorageMonitorWin* msg_wnd =
148 reinterpret_cast<RemovableDeviceNotificationsWindowWin*>( 148 reinterpret_cast<StorageMonitorWin*>(
149 GetWindowLongPtr(hwnd, GWLP_USERDATA)); 149 GetWindowLongPtr(hwnd, GWLP_USERDATA));
vandebo (ex-Chrome) 2013/03/01 19:47:39 nit: line wrap.
150 if (msg_wnd) 150 if (msg_wnd)
151 return msg_wnd->WndProc(hwnd, message, wparam, lparam); 151 return msg_wnd->WndProc(hwnd, message, wparam, lparam);
152 return ::DefWindowProc(hwnd, message, wparam, lparam); 152 return ::DefWindowProc(hwnd, message, wparam, lparam);
153 } 153 }
154 154
155 LRESULT CALLBACK RemovableDeviceNotificationsWindowWin::WndProc( 155 LRESULT CALLBACK StorageMonitorWin::WndProc(
156 HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) { 156 HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) {
vandebo (ex-Chrome) 2013/03/01 19:47:39 nit: line wrap.
157 switch (message) { 157 switch (message) {
158 case WM_DEVICECHANGE: 158 case WM_DEVICECHANGE:
159 OnDeviceChange(static_cast<UINT>(wparam), lparam); 159 OnDeviceChange(static_cast<UINT>(wparam), lparam);
160 return TRUE; 160 return TRUE;
161 default: 161 default:
162 break; 162 break;
163 } 163 }
164 164
165 return ::DefWindowProc(hwnd, message, wparam, lparam); 165 return ::DefWindowProc(hwnd, message, wparam, lparam);
166 } 166 }
167 167
168 bool RemovableDeviceNotificationsWindowWin::GetDeviceInfo( 168 bool StorageMonitorWin::GetDeviceInfo(
169 const base::FilePath& device_path, string16* device_location, 169 const base::FilePath& device_path, string16* device_location,
170 std::string* unique_id, string16* name, bool* removable, 170 std::string* unique_id, string16* name, bool* removable,
171 uint64* total_size_in_bytes) const { 171 uint64* total_size_in_bytes) const {
vandebo (ex-Chrome) 2013/03/01 19:47:39 reindent; one arg per line, aligned after (
172 // TODO(kmadhusu) Implement PortableDeviceWatcherWin::GetDeviceInfo() 172 // TODO(kmadhusu) Implement PortableDeviceWatcherWin::GetDeviceInfo()
173 // function when we have the functionality to add a sub directory of 173 // function when we have the functionality to add a sub directory of
174 // portable device as a media gallery. 174 // portable device as a media gallery.
175 return volume_mount_watcher_->GetDeviceInfo(device_path, device_location, 175 return volume_mount_watcher_->GetDeviceInfo(device_path, device_location,
176 unique_id, name, removable, 176 unique_id, name, removable,
177 total_size_in_bytes); 177 total_size_in_bytes);
178 } 178 }
179 179
180 void RemovableDeviceNotificationsWindowWin::OnDeviceChange(UINT event_type, 180 void StorageMonitorWin::OnDeviceChange(UINT event_type,
181 LPARAM data) { 181 LPARAM data) {
vandebo (ex-Chrome) 2013/03/01 19:47:39 nit: line wrap.
182 volume_mount_watcher_->OnWindowMessage(event_type, data); 182 volume_mount_watcher_->OnWindowMessage(event_type, data);
183 portable_device_watcher_->OnWindowMessage(event_type, data); 183 portable_device_watcher_->OnWindowMessage(event_type, data);
184 } 184 }
185 185
186 } // namespace chrome 186 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698