OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/options/chromeos/storage_manager_handler.h" | 5 #include "chrome/browser/ui/webui/options/chromeos/storage_manager_handler.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/sys_info.h" | 10 #include "base/sys_info.h" |
11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/chromeos/arc/arc_auth_service.h" | 12 #include "chrome/browser/chromeos/arc/arc_auth_service.h" |
| 13 #include "chrome/browser/chromeos/drive/file_system_util.h" |
13 #include "chrome/browser/chromeos/file_manager/path_util.h" | 14 #include "chrome/browser/chromeos/file_manager/path_util.h" |
14 #include "chrome/browser/platform_util.h" | 15 #include "chrome/browser/platform_util.h" |
15 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/grit/generated_resources.h" | 17 #include "chrome/grit/generated_resources.h" |
| 18 #include "components/drive/chromeos/file_system_interface.h" |
17 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
18 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
19 #include "ui/base/text/bytes_formatting.h" | 21 #include "ui/base/text/bytes_formatting.h" |
20 | 22 |
21 namespace chromeos { | 23 namespace chromeos { |
22 namespace options { | 24 namespace options { |
23 namespace { | 25 namespace { |
24 | 26 |
25 void GetSizeStatOnBlockingPool(const base::FilePath& mount_path, | 27 void GetSizeStatOnBlockingPool(const base::FilePath& mount_path, |
26 int64_t* total_size, | 28 int64_t* total_size, |
(...skipping 13 matching lines...) Expand all Loading... |
40 | 42 |
41 StorageManagerHandler::~StorageManagerHandler() { | 43 StorageManagerHandler::~StorageManagerHandler() { |
42 } | 44 } |
43 | 45 |
44 void StorageManagerHandler::GetLocalizedValues( | 46 void StorageManagerHandler::GetLocalizedValues( |
45 base::DictionaryValue* localized_strings) { | 47 base::DictionaryValue* localized_strings) { |
46 DCHECK(localized_strings); | 48 DCHECK(localized_strings); |
47 | 49 |
48 RegisterTitle(localized_strings, "storageManagerPage", | 50 RegisterTitle(localized_strings, "storageManagerPage", |
49 IDS_OPTIONS_SETTINGS_STORAGE_MANAGER_TAB_TITLE); | 51 IDS_OPTIONS_SETTINGS_STORAGE_MANAGER_TAB_TITLE); |
| 52 RegisterTitle(localized_strings, "storageClearDriveCachePage", |
| 53 IDS_OPTIONS_SETTINGS_STORAGE_CLEAR_DRIVE_CACHE_TAB_TITLE); |
50 | 54 |
51 localized_strings->SetString( | 55 localized_strings->SetString( |
52 "storageItemLabelCapacity", l10n_util::GetStringUTF16( | 56 "storageItemLabelCapacity", l10n_util::GetStringUTF16( |
53 IDS_OPTIONS_SETTINGS_STORAGE_ITEM_LABEL_CAPACITY)); | 57 IDS_OPTIONS_SETTINGS_STORAGE_ITEM_LABEL_CAPACITY)); |
54 localized_strings->SetString( | 58 localized_strings->SetString( |
55 "storageItemLabelInUse", l10n_util::GetStringUTF16( | 59 "storageItemLabelInUse", l10n_util::GetStringUTF16( |
56 IDS_OPTIONS_SETTINGS_STORAGE_ITEM_LABEL_IN_USE)); | 60 IDS_OPTIONS_SETTINGS_STORAGE_ITEM_LABEL_IN_USE)); |
57 localized_strings->SetString( | 61 localized_strings->SetString( |
58 "storageItemLabelAvailable", l10n_util::GetStringUTF16( | 62 "storageItemLabelAvailable", l10n_util::GetStringUTF16( |
59 IDS_OPTIONS_SETTINGS_STORAGE_ITEM_LABEL_AVAILABLE)); | 63 IDS_OPTIONS_SETTINGS_STORAGE_ITEM_LABEL_AVAILABLE)); |
60 localized_strings->SetString( | 64 localized_strings->SetString( |
61 "storageSubitemLabelDownloads", l10n_util::GetStringUTF16( | 65 "storageSubitemLabelDownloads", l10n_util::GetStringUTF16( |
62 IDS_OPTIONS_SETTINGS_STORAGE_SUBITEM_LABEL_DOWNLOADS)); | 66 IDS_OPTIONS_SETTINGS_STORAGE_SUBITEM_LABEL_DOWNLOADS)); |
63 localized_strings->SetString( | 67 localized_strings->SetString( |
| 68 "storageSubitemLabelDriveCache", l10n_util::GetStringUTF16( |
| 69 IDS_OPTIONS_SETTINGS_STORAGE_SUBITEM_LABEL_DRIVE_CACHE)); |
| 70 localized_strings->SetString( |
64 "storageSubitemLabelArc", l10n_util::GetStringUTF16( | 71 "storageSubitemLabelArc", l10n_util::GetStringUTF16( |
65 IDS_OPTIONS_SETTINGS_STORAGE_SUBITEM_LABEL_ARC)); | 72 IDS_OPTIONS_SETTINGS_STORAGE_SUBITEM_LABEL_ARC)); |
66 localized_strings->SetString( | 73 localized_strings->SetString( |
67 "storageSizeCalculating", l10n_util::GetStringUTF16( | 74 "storageSizeCalculating", l10n_util::GetStringUTF16( |
68 IDS_OPTIONS_SETTINGS_STORAGE_SIZE_CALCULATING)); | 75 IDS_OPTIONS_SETTINGS_STORAGE_SIZE_CALCULATING)); |
| 76 localized_strings->SetString( |
| 77 "storageClearDriveCacheDescription", l10n_util::GetStringUTF16( |
| 78 IDS_OPTIONS_SETTINGS_STORAGE_CLEAR_DRIVE_CACHE_DESCRIPTION)); |
| 79 localized_strings->SetString( |
| 80 "storageDeleteAllButtonTitle", l10n_util::GetStringUTF16( |
| 81 IDS_OPTIONS_SETTINGS_STORAGE_DELETE_ALL_BUTTON_TITLE)); |
69 } | 82 } |
70 | 83 |
71 void StorageManagerHandler::InitializePage() { | 84 void StorageManagerHandler::InitializePage() { |
72 DCHECK(web_ui()); | 85 DCHECK(web_ui()); |
73 } | 86 } |
74 | 87 |
75 void StorageManagerHandler::RegisterMessages() { | 88 void StorageManagerHandler::RegisterMessages() { |
76 DCHECK(web_ui()); | 89 DCHECK(web_ui()); |
77 | 90 |
78 web_ui()->RegisterMessageCallback( | 91 web_ui()->RegisterMessageCallback( |
79 "updateStorageInfo", | 92 "updateStorageInfo", |
80 base::Bind(&StorageManagerHandler::HandleUpdateStorageInfo, | 93 base::Bind(&StorageManagerHandler::HandleUpdateStorageInfo, |
81 base::Unretained(this))); | 94 base::Unretained(this))); |
82 web_ui()->RegisterMessageCallback( | 95 web_ui()->RegisterMessageCallback( |
83 "openDownloads", | 96 "openDownloads", |
84 base::Bind(&StorageManagerHandler::HandleOpenDownloads, | 97 base::Bind(&StorageManagerHandler::HandleOpenDownloads, |
85 base::Unretained(this))); | 98 base::Unretained(this))); |
86 web_ui()->RegisterMessageCallback( | 99 web_ui()->RegisterMessageCallback( |
87 "openArcStorage", | 100 "openArcStorage", |
88 base::Bind(&StorageManagerHandler::HandleOpenArcStorage, | 101 base::Bind(&StorageManagerHandler::HandleOpenArcStorage, |
89 base::Unretained(this))); | 102 base::Unretained(this))); |
| 103 web_ui()->RegisterMessageCallback( |
| 104 "clearDriveCache", |
| 105 base::Bind(&StorageManagerHandler::HandleClearDriveCache, |
| 106 base::Unretained(this))); |
90 } | 107 } |
91 | 108 |
92 void StorageManagerHandler::HandleUpdateStorageInfo( | 109 void StorageManagerHandler::HandleUpdateStorageInfo( |
93 const base::ListValue* unused_args) { | 110 const base::ListValue* unused_args) { |
94 UpdateSizeStat(); | 111 UpdateSizeStat(); |
95 UpdateDownloadsSize(); | 112 UpdateDownloadsSize(); |
| 113 UpdateDriveCacheSize(); |
96 UpdateArcSize(); | 114 UpdateArcSize(); |
97 } | 115 } |
98 | 116 |
99 void StorageManagerHandler::HandleOpenDownloads( | 117 void StorageManagerHandler::HandleOpenDownloads( |
100 const base::ListValue* unused_args) { | 118 const base::ListValue* unused_args) { |
101 Profile* const profile = Profile::FromWebUI(web_ui()); | 119 Profile* const profile = Profile::FromWebUI(web_ui()); |
102 const base::FilePath downloads_path = | 120 const base::FilePath downloads_path = |
103 file_manager::util::GetDownloadsFolderForProfile(profile); | 121 file_manager::util::GetDownloadsFolderForProfile(profile); |
104 platform_util::OpenItem( | 122 platform_util::OpenItem( |
105 profile, | 123 profile, |
106 downloads_path, | 124 downloads_path, |
107 platform_util::OPEN_FOLDER, | 125 platform_util::OPEN_FOLDER, |
108 platform_util::OpenOperationCallback()); | 126 platform_util::OpenOperationCallback()); |
109 } | 127 } |
110 | 128 |
111 void StorageManagerHandler::HandleOpenArcStorage( | 129 void StorageManagerHandler::HandleOpenArcStorage( |
112 const base::ListValue* unused_args) { | 130 const base::ListValue* unused_args) { |
113 arc::ArcStorageManager::Get()->OpenPrivateVolumeSettings(); | 131 arc::ArcStorageManager::Get()->OpenPrivateVolumeSettings(); |
114 } | 132 } |
115 | 133 |
| 134 void StorageManagerHandler::HandleClearDriveCache( |
| 135 const base::ListValue* unused_args) { |
| 136 drive::FileSystemInterface* const file_system = |
| 137 drive::util::GetFileSystemByProfile(Profile::FromWebUI(web_ui())); |
| 138 file_system->FreeDiskSpaceIfNeededFor( |
| 139 std::numeric_limits<int64_t>::max(), // Removes as much as possible. |
| 140 base::Bind(&StorageManagerHandler::OnClearDriveCacheDone, |
| 141 weak_ptr_factory_.GetWeakPtr())); |
| 142 } |
| 143 |
116 void StorageManagerHandler::UpdateSizeStat() { | 144 void StorageManagerHandler::UpdateSizeStat() { |
117 Profile* const profile = Profile::FromWebUI(web_ui()); | 145 Profile* const profile = Profile::FromWebUI(web_ui()); |
118 const base::FilePath downloads_path = | 146 const base::FilePath downloads_path = |
119 file_manager::util::GetDownloadsFolderForProfile(profile); | 147 file_manager::util::GetDownloadsFolderForProfile(profile); |
120 | 148 |
121 int64_t* total_size = new int64_t(0); | 149 int64_t* total_size = new int64_t(0); |
122 int64_t* available_size = new int64_t(0); | 150 int64_t* available_size = new int64_t(0); |
123 content::BrowserThread::PostBlockingPoolTaskAndReply( | 151 content::BrowserThread::PostBlockingPoolTaskAndReply( |
124 FROM_HERE, | 152 FROM_HERE, |
125 base::Bind(&GetSizeStatOnBlockingPool, | 153 base::Bind(&GetSizeStatOnBlockingPool, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 base::Bind(&StorageManagerHandler::OnGetDownloadsSize, | 185 base::Bind(&StorageManagerHandler::OnGetDownloadsSize, |
158 weak_ptr_factory_.GetWeakPtr())); | 186 weak_ptr_factory_.GetWeakPtr())); |
159 } | 187 } |
160 | 188 |
161 void StorageManagerHandler::OnGetDownloadsSize(int64_t size) { | 189 void StorageManagerHandler::OnGetDownloadsSize(int64_t size) { |
162 web_ui()->CallJavascriptFunctionUnsafe( | 190 web_ui()->CallJavascriptFunctionUnsafe( |
163 "options.StorageManager.setDownloadsSize", | 191 "options.StorageManager.setDownloadsSize", |
164 base::StringValue(ui::FormatBytes(size))); | 192 base::StringValue(ui::FormatBytes(size))); |
165 } | 193 } |
166 | 194 |
| 195 void StorageManagerHandler::UpdateDriveCacheSize() { |
| 196 drive::FileSystemInterface* const file_system = |
| 197 drive::util::GetFileSystemByProfile(Profile::FromWebUI(web_ui())); |
| 198 file_system->CalculateCacheSize( |
| 199 base::Bind(&StorageManagerHandler::OnGetDriveCacheSize, |
| 200 weak_ptr_factory_.GetWeakPtr())); |
| 201 } |
| 202 |
| 203 void StorageManagerHandler::OnGetDriveCacheSize(int64_t size) { |
| 204 web_ui()->CallJavascriptFunctionUnsafe( |
| 205 "options.StorageManager.setDriveCacheSize", |
| 206 base::StringValue(ui::FormatBytes(size))); |
| 207 } |
| 208 |
167 void StorageManagerHandler::UpdateArcSize() { | 209 void StorageManagerHandler::UpdateArcSize() { |
168 Profile* const profile = Profile::FromWebUI(web_ui()); | 210 Profile* const profile = Profile::FromWebUI(web_ui()); |
169 if (!arc::ArcAuthService::IsAllowedForProfile(profile) || | 211 if (!arc::ArcAuthService::IsAllowedForProfile(profile) || |
170 arc::ArcAuthService::IsOptInVerificationDisabled() || | 212 arc::ArcAuthService::IsOptInVerificationDisabled() || |
171 !arc::ArcAuthService::Get()->IsArcEnabled()) { | 213 !arc::ArcAuthService::Get()->IsArcEnabled()) { |
172 return; | 214 return; |
173 } | 215 } |
174 | 216 |
175 // Shows the item "Android apps and cache" and start calculating size. | 217 // Shows the item "Android apps and cache" and start calculating size. |
176 web_ui()->CallJavascriptFunctionUnsafe( | 218 web_ui()->CallJavascriptFunctionUnsafe( |
(...skipping 18 matching lines...) Expand all Loading... |
195 if (succeeded) { | 237 if (succeeded) { |
196 uint64_t total_bytes = size->total_code_bytes + | 238 uint64_t total_bytes = size->total_code_bytes + |
197 size->total_data_bytes + | 239 size->total_data_bytes + |
198 size->total_cache_bytes; | 240 size->total_cache_bytes; |
199 arc_size = base::StringValue(ui::FormatBytes(total_bytes)); | 241 arc_size = base::StringValue(ui::FormatBytes(total_bytes)); |
200 } | 242 } |
201 web_ui()->CallJavascriptFunctionUnsafe("options.StorageManager.setArcSize", | 243 web_ui()->CallJavascriptFunctionUnsafe("options.StorageManager.setArcSize", |
202 arc_size); | 244 arc_size); |
203 } | 245 } |
204 | 246 |
| 247 void StorageManagerHandler::OnClearDriveCacheDone(bool success) { |
| 248 UpdateDriveCacheSize(); |
| 249 } |
| 250 |
205 } // namespace options | 251 } // namespace options |
206 } // namespace chromeos | 252 } // namespace chromeos |
OLD | NEW |