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

Side by Side Diff: chrome/browser/ui/webui/offline/offline_internals_ui_message_handler.cc

Issue 2821563002: [Offline Pages] Fix crash in chrome://offline-internals (Closed)
Patch Set: Created 3 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <vector> 9 #include <vector>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/guid.h" 12 #include "base/guid.h"
13 #include "base/memory/ptr_util.h"
13 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
14 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h" 15 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h"
15 #include "chrome/browser/android/offline_pages/request_coordinator_factory.h" 16 #include "chrome/browser/android/offline_pages/request_coordinator_factory.h"
16 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
17 #include "components/offline_pages/core/client_namespace_constants.h" 18 #include "components/offline_pages/core/client_namespace_constants.h"
18 #include "content/public/browser/web_ui.h" 19 #include "content/public/browser/web_ui.h"
19 #include "net/base/network_change_notifier.h" 20 #include "net/base/network_change_notifier.h"
20 21
21 namespace offline_internals { 22 namespace offline_internals {
22 23
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 base::Value(callback_id), 127 base::Value(callback_id),
127 base::Value(GetStringFromDeleteRequestResults(results))); 128 base::Value(GetStringFromDeleteRequestResults(results)));
128 } 129 }
129 130
130 void OfflineInternalsUIMessageHandler::HandleStoredPagesCallback( 131 void OfflineInternalsUIMessageHandler::HandleStoredPagesCallback(
131 std::string callback_id, 132 std::string callback_id,
132 const offline_pages::MultipleOfflinePageItemResult& pages) { 133 const offline_pages::MultipleOfflinePageItemResult& pages) {
133 base::ListValue results; 134 base::ListValue results;
134 135
135 for (const auto& page : pages) { 136 for (const auto& page : pages) {
136 base::DictionaryValue* offline_page = new base::DictionaryValue(); 137 auto offline_page = base::MakeUnique<base::DictionaryValue>();
137 results.Append(offline_page);
138 offline_page->SetString("onlineUrl", page.url.spec()); 138 offline_page->SetString("onlineUrl", page.url.spec());
139 offline_page->SetString("namespace", page.client_id.name_space); 139 offline_page->SetString("namespace", page.client_id.name_space);
140 offline_page->SetDouble("size", page.file_size); 140 offline_page->SetDouble("size", page.file_size);
141 offline_page->SetString("id", std::to_string(page.offline_id)); 141 offline_page->SetString("id", std::to_string(page.offline_id));
142 offline_page->SetString("filePath", page.file_path.MaybeAsASCII()); 142 offline_page->SetString("filePath", page.file_path.MaybeAsASCII());
143 offline_page->SetDouble("creationTime", page.creation_time.ToJsTime()); 143 offline_page->SetDouble("creationTime", page.creation_time.ToJsTime());
144 offline_page->SetDouble("lastAccessTime", page.last_access_time.ToJsTime()); 144 offline_page->SetDouble("lastAccessTime", page.last_access_time.ToJsTime());
145 offline_page->SetInteger("accessCount", page.access_count); 145 offline_page->SetInteger("accessCount", page.access_count);
146 offline_page->SetString("originalUrl", page.original_url.spec()); 146 offline_page->SetString("originalUrl", page.original_url.spec());
147 results.Append(std::move(offline_page));
147 } 148 }
148 ResolveJavascriptCallback(base::Value(callback_id), results); 149 ResolveJavascriptCallback(base::Value(callback_id), results);
149 } 150 }
150 151
151 void OfflineInternalsUIMessageHandler::HandleRequestQueueCallback( 152 void OfflineInternalsUIMessageHandler::HandleRequestQueueCallback(
152 std::string callback_id, 153 std::string callback_id,
153 offline_pages::GetRequestsResult result, 154 offline_pages::GetRequestsResult result,
154 std::vector<std::unique_ptr<offline_pages::SavePageRequest>> requests) { 155 std::vector<std::unique_ptr<offline_pages::SavePageRequest>> requests) {
155 base::ListValue save_page_requests; 156 base::ListValue save_page_requests;
156 if (result == offline_pages::GetRequestsResult::SUCCESS) { 157 if (result == offline_pages::GetRequestsResult::SUCCESS) {
157 for (const auto& request : requests) { 158 for (const auto& request : requests) {
158 base::DictionaryValue* save_page_request = new base::DictionaryValue(); 159 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()); 160 save_page_request->SetString("onlineUrl", request->url().spec());
161 save_page_request->SetDouble("creationTime", 161 save_page_request->SetDouble("creationTime",
162 request->creation_time().ToJsTime()); 162 request->creation_time().ToJsTime());
163 save_page_request->SetString("status", GetStringFromSavePageStatus()); 163 save_page_request->SetString("status", GetStringFromSavePageStatus());
164 save_page_request->SetString("namespace", 164 save_page_request->SetString("namespace",
165 request->client_id().name_space); 165 request->client_id().name_space);
166 save_page_request->SetDouble("lastAttempt", 166 save_page_request->SetDouble("lastAttempt",
167 request->last_attempt_time().ToJsTime()); 167 request->last_attempt_time().ToJsTime());
168 save_page_request->SetString("id", std::to_string(request->request_id())); 168 save_page_request->SetString("id", std::to_string(request->request_id()));
169 save_page_request->SetString("originalUrl", 169 save_page_request->SetString("originalUrl",
170 request->original_url().spec()); 170 request->original_url().spec());
171 save_page_requests.Append(std::move(save_page_request));
171 } 172 }
172 } 173 }
173 ResolveJavascriptCallback(base::Value(callback_id), save_page_requests); 174 ResolveJavascriptCallback(base::Value(callback_id), save_page_requests);
174 } 175 }
175 176
176 void OfflineInternalsUIMessageHandler::HandleGetRequestQueue( 177 void OfflineInternalsUIMessageHandler::HandleGetRequestQueue(
177 const base::ListValue* args) { 178 const base::ListValue* args) {
178 AllowJavascript(); 179 AllowJavascript();
179 std::string callback_id; 180 std::string callback_id;
180 CHECK(args->GetString(0, &callback_id)); 181 CHECK(args->GetString(0, &callback_id));
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 341
341 // Get the offline page model associated with this web ui. 342 // Get the offline page model associated with this web ui.
342 Profile* profile = Profile::FromWebUI(web_ui()); 343 Profile* profile = Profile::FromWebUI(web_ui());
343 offline_page_model_ = 344 offline_page_model_ =
344 offline_pages::OfflinePageModelFactory::GetForBrowserContext(profile); 345 offline_pages::OfflinePageModelFactory::GetForBrowserContext(profile);
345 request_coordinator_ = 346 request_coordinator_ =
346 offline_pages::RequestCoordinatorFactory::GetForBrowserContext(profile); 347 offline_pages::RequestCoordinatorFactory::GetForBrowserContext(profile);
347 } 348 }
348 349
349 } // namespace offline_internals 350 } // namespace offline_internals
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698