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

Side by Side Diff: chrome/browser/android/offline_pages/prerendering_offliner.cc

Issue 2683493002: Get signals working in the EXTRA_DATA section of MHTML (Closed)
Patch Set: Don't forget the new .h file Created 3 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 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/android/offline_pages/prerendering_offliner.h" 5 #include "chrome/browser/android/offline_pages/prerendering_offliner.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/metrics/histogram_macros.h" 8 #include "base/metrics/histogram_macros.h"
9 #include "base/sys_info.h" 9 #include "base/sys_info.h"
10 #include "chrome/browser/android/offline_pages/offline_page_mhtml_archiver.h" 10 #include "chrome/browser/android/offline_pages/offline_page_mhtml_archiver.h"
11 #include "chrome/browser/android/offline_pages/offliner_helper.h" 11 #include "chrome/browser/android/offline_pages/offliner_helper.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "components/offline_pages/core/background/offliner_policy.h" 13 #include "components/offline_pages/core/background/offliner_policy.h"
14 #include "components/offline_pages/core/background/save_page_request.h" 14 #include "components/offline_pages/core/background/save_page_request.h"
15 #include "components/offline_pages/core/client_namespace_constants.h" 15 #include "components/offline_pages/core/client_namespace_constants.h"
16 #include "components/offline_pages/core/downloads/download_ui_adapter.h" 16 #include "components/offline_pages/core/downloads/download_ui_adapter.h"
17 #include "components/offline_pages/core/offline_page_model.h" 17 #include "components/offline_pages/core/offline_page_model.h"
18 #include "content/browser/download/mhtml_extra_data.h"
18 #include "content/public/browser/browser_context.h" 19 #include "content/public/browser/browser_context.h"
19 #include "content/public/browser/web_contents.h" 20 #include "content/public/browser/web_contents.h"
20 21
21 namespace offline_pages { 22 namespace offline_pages {
22 23
23 PrerenderingOffliner::PrerenderingOffliner( 24 PrerenderingOffliner::PrerenderingOffliner(
24 content::BrowserContext* browser_context, 25 content::BrowserContext* browser_context,
25 const OfflinerPolicy* policy, 26 const OfflinerPolicy* policy,
26 OfflinePageModel* offline_page_model) 27 OfflinePageModel* offline_page_model)
27 : browser_context_(browser_context), 28 : browser_context_(browser_context),
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 save_page_params.client_id = request.client_id(); 77 save_page_params.client_id = request.client_id();
77 save_page_params.proposed_offline_id = request.request_id(); 78 save_page_params.proposed_offline_id = request.request_id();
78 save_page_params.is_background = true; 79 save_page_params.is_background = true;
79 // Pass in the original URL if it is different from the last committed URL 80 // Pass in the original URL if it is different from the last committed URL
80 // when redirects occur. 81 // when redirects occur.
81 if (!request.original_url().is_empty()) 82 if (!request.original_url().is_empty())
82 save_page_params.original_url = request.original_url(); 83 save_page_params.original_url = request.original_url();
83 else if (save_page_params.url != request.url()) 84 else if (save_page_params.url != request.url())
84 save_page_params.original_url = request.url(); 85 save_page_params.original_url = request.url();
85 86
87 // Write the signal data into a single string.
88 const char kContentTypeLine[] = "Content-Type: application/json\r\n";
Dmitry Titov 2017/03/16 02:28:20 this line would normally be at the beginning of th
Pete Williamson 2017/03/17 23:28:32 Done.
89 std::string signal_string(kContentTypeLine);
90 const std::vector<std::string>& signals = loader_->GetSignalData();
91
92 // TODO(petewil): Convert this to JSON.
93 for (std::string signal : signals) {
Dmitry Titov 2017/03/16 02:28:20 I'd move this whole block into a separate function
Pete Williamson 2017/03/17 23:28:32 Done.
94 signal_string += signal;
95 signal_string += "\r\n";
96 }
97
98 // Attach the signal data to the web contents.
99 web_contents->SetUserData(content::kMHTMLExtraDataKey,
100 std::unique_ptr<base::SupportsUserData::Data>(
101 new content::MHTMLExtraData(signal_string)));
102
86 SavePage(save_page_params, std::move(archiver), 103 SavePage(save_page_params, std::move(archiver),
87 base::Bind(&PrerenderingOffliner::OnSavePageDone, 104 base::Bind(&PrerenderingOffliner::OnSavePageDone,
88 weak_ptr_factory_.GetWeakPtr(), request)); 105 weak_ptr_factory_.GetWeakPtr(), request));
89 } else { 106 } else {
90 // Clear pending request and app listener then run completion callback. 107 // Clear pending request and app listener then run completion callback.
91 pending_request_.reset(nullptr); 108 pending_request_.reset(nullptr);
92 app_listener_.reset(nullptr); 109 app_listener_.reset(nullptr);
93 completion_callback_.Run(request, load_status); 110 completion_callback_.Run(request, load_status);
94 } 111 }
95 } 112 }
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 void PrerenderingOffliner::HandleApplicationStateChangeCancel( 300 void PrerenderingOffliner::HandleApplicationStateChangeCancel(
284 const SavePageRequest& request, 301 const SavePageRequest& request,
285 int64_t offline_id) { 302 int64_t offline_id) {
286 // This shouldn't be immediate, but account for case where request was reset 303 // This shouldn't be immediate, but account for case where request was reset
287 // while waiting for callback. 304 // while waiting for callback.
288 if (pending_request_ && pending_request_->request_id() != offline_id) 305 if (pending_request_ && pending_request_->request_id() != offline_id)
289 return; 306 return;
290 completion_callback_.Run(request, RequestStatus::FOREGROUND_CANCELED); 307 completion_callback_.Run(request, RequestStatus::FOREGROUND_CANCELED);
291 } 308 }
292 } // namespace offline_pages 309 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698