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/offline/offline_internals_ui_message_handler.h
" | 5 #include "chrome/browser/ui/webui/offline/offline_internals_ui_message_handler.h
" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <stdlib.h> | 8 #include <stdlib.h> |
| 9 #include <utility> |
9 #include <vector> | 10 #include <vector> |
10 | 11 |
11 #include "base/bind.h" | 12 #include "base/bind.h" |
12 #include "base/guid.h" | 13 #include "base/guid.h" |
| 14 #include "base/memory/ptr_util.h" |
13 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 16 #include "base/values.h" |
14 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h" | 17 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h" |
15 #include "chrome/browser/android/offline_pages/request_coordinator_factory.h" | 18 #include "chrome/browser/android/offline_pages/request_coordinator_factory.h" |
16 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
17 #include "components/offline_pages/core/client_namespace_constants.h" | 20 #include "components/offline_pages/core/client_namespace_constants.h" |
18 #include "content/public/browser/web_ui.h" | 21 #include "content/public/browser/web_ui.h" |
19 #include "net/base/network_change_notifier.h" | 22 #include "net/base/network_change_notifier.h" |
20 | 23 |
21 namespace offline_internals { | 24 namespace offline_internals { |
22 | 25 |
23 OfflineInternalsUIMessageHandler::OfflineInternalsUIMessageHandler() | 26 OfflineInternalsUIMessageHandler::OfflineInternalsUIMessageHandler() |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 base::Value(callback_id), | 129 base::Value(callback_id), |
127 base::Value(GetStringFromDeleteRequestResults(results))); | 130 base::Value(GetStringFromDeleteRequestResults(results))); |
128 } | 131 } |
129 | 132 |
130 void OfflineInternalsUIMessageHandler::HandleStoredPagesCallback( | 133 void OfflineInternalsUIMessageHandler::HandleStoredPagesCallback( |
131 std::string callback_id, | 134 std::string callback_id, |
132 const offline_pages::MultipleOfflinePageItemResult& pages) { | 135 const offline_pages::MultipleOfflinePageItemResult& pages) { |
133 base::ListValue results; | 136 base::ListValue results; |
134 | 137 |
135 for (const auto& page : pages) { | 138 for (const auto& page : pages) { |
136 base::DictionaryValue* offline_page = new base::DictionaryValue(); | 139 auto offline_page = base::MakeUnique<base::DictionaryValue>(); |
137 results.Append(offline_page); | |
138 offline_page->SetString("onlineUrl", page.url.spec()); | 140 offline_page->SetString("onlineUrl", page.url.spec()); |
139 offline_page->SetString("namespace", page.client_id.name_space); | 141 offline_page->SetString("namespace", page.client_id.name_space); |
140 offline_page->SetDouble("size", page.file_size); | 142 offline_page->SetDouble("size", page.file_size); |
141 offline_page->SetString("id", std::to_string(page.offline_id)); | 143 offline_page->SetString("id", std::to_string(page.offline_id)); |
142 offline_page->SetString("filePath", page.file_path.MaybeAsASCII()); | 144 offline_page->SetString("filePath", page.file_path.MaybeAsASCII()); |
143 offline_page->SetDouble("creationTime", page.creation_time.ToJsTime()); | 145 offline_page->SetDouble("creationTime", page.creation_time.ToJsTime()); |
144 offline_page->SetDouble("lastAccessTime", page.last_access_time.ToJsTime()); | 146 offline_page->SetDouble("lastAccessTime", page.last_access_time.ToJsTime()); |
145 offline_page->SetInteger("accessCount", page.access_count); | 147 offline_page->SetInteger("accessCount", page.access_count); |
146 offline_page->SetString("originalUrl", page.original_url.spec()); | 148 offline_page->SetString("originalUrl", page.original_url.spec()); |
| 149 results.Append(std::move(offline_page)); |
147 } | 150 } |
148 ResolveJavascriptCallback(base::Value(callback_id), results); | 151 ResolveJavascriptCallback(base::Value(callback_id), results); |
149 } | 152 } |
150 | 153 |
151 void OfflineInternalsUIMessageHandler::HandleRequestQueueCallback( | 154 void OfflineInternalsUIMessageHandler::HandleRequestQueueCallback( |
152 std::string callback_id, | 155 std::string callback_id, |
153 offline_pages::GetRequestsResult result, | 156 offline_pages::GetRequestsResult result, |
154 std::vector<std::unique_ptr<offline_pages::SavePageRequest>> requests) { | 157 std::vector<std::unique_ptr<offline_pages::SavePageRequest>> requests) { |
155 base::ListValue save_page_requests; | 158 base::ListValue save_page_requests; |
156 if (result == offline_pages::GetRequestsResult::SUCCESS) { | 159 if (result == offline_pages::GetRequestsResult::SUCCESS) { |
157 for (const auto& request : requests) { | 160 for (const auto& request : requests) { |
158 base::DictionaryValue* save_page_request = new base::DictionaryValue(); | 161 auto save_page_request = base::MakeUnique<base::DictionaryValue>(); |
159 save_page_requests.Append(save_page_request); | |
160 save_page_request->SetString("onlineUrl", request->url().spec()); | 162 save_page_request->SetString("onlineUrl", request->url().spec()); |
161 save_page_request->SetDouble("creationTime", | 163 save_page_request->SetDouble("creationTime", |
162 request->creation_time().ToJsTime()); | 164 request->creation_time().ToJsTime()); |
163 save_page_request->SetString("status", GetStringFromSavePageStatus()); | 165 save_page_request->SetString("status", GetStringFromSavePageStatus()); |
164 save_page_request->SetString("namespace", | 166 save_page_request->SetString("namespace", |
165 request->client_id().name_space); | 167 request->client_id().name_space); |
166 save_page_request->SetDouble("lastAttempt", | 168 save_page_request->SetDouble("lastAttempt", |
167 request->last_attempt_time().ToJsTime()); | 169 request->last_attempt_time().ToJsTime()); |
168 save_page_request->SetString("id", std::to_string(request->request_id())); | 170 save_page_request->SetString("id", std::to_string(request->request_id())); |
169 save_page_request->SetString("originalUrl", | 171 save_page_request->SetString("originalUrl", |
170 request->original_url().spec()); | 172 request->original_url().spec()); |
| 173 save_page_requests.Append(std::move(save_page_request)); |
171 } | 174 } |
172 } | 175 } |
173 ResolveJavascriptCallback(base::Value(callback_id), save_page_requests); | 176 ResolveJavascriptCallback(base::Value(callback_id), save_page_requests); |
174 } | 177 } |
175 | 178 |
176 void OfflineInternalsUIMessageHandler::HandleGetRequestQueue( | 179 void OfflineInternalsUIMessageHandler::HandleGetRequestQueue( |
177 const base::ListValue* args) { | 180 const base::ListValue* args) { |
178 AllowJavascript(); | 181 AllowJavascript(); |
179 std::string callback_id; | 182 std::string callback_id; |
180 CHECK(args->GetString(0, &callback_id)); | 183 CHECK(args->GetString(0, &callback_id)); |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 | 343 |
341 // Get the offline page model associated with this web ui. | 344 // Get the offline page model associated with this web ui. |
342 Profile* profile = Profile::FromWebUI(web_ui()); | 345 Profile* profile = Profile::FromWebUI(web_ui()); |
343 offline_page_model_ = | 346 offline_page_model_ = |
344 offline_pages::OfflinePageModelFactory::GetForBrowserContext(profile); | 347 offline_pages::OfflinePageModelFactory::GetForBrowserContext(profile); |
345 request_coordinator_ = | 348 request_coordinator_ = |
346 offline_pages::RequestCoordinatorFactory::GetForBrowserContext(profile); | 349 offline_pages::RequestCoordinatorFactory::GetForBrowserContext(profile); |
347 } | 350 } |
348 | 351 |
349 } // namespace offline_internals | 352 } // namespace offline_internals |
OLD | NEW |