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

Side by Side Diff: chrome/browser/ui/webui/print_preview_ui.cc

Issue 7365003: Print Preview: Make preview generation event driven to eliminate synchronous messages. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: clang fix Created 9 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/webui/print_preview_ui.h ('k') | chrome/common/print_messages.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/print_preview_ui.h" 5 #include "chrome/browser/ui/webui/print_preview_ui.h"
6 6
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/printing/print_preview_data_service.h" 10 #include "chrome/browser/printing/print_preview_data_service.h"
11 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/ui/webui/print_preview_data_source.h" 12 #include "chrome/browser/ui/webui/print_preview_data_source.h"
13 #include "chrome/browser/ui/webui/print_preview_handler.h" 13 #include "chrome/browser/ui/webui/print_preview_handler.h"
14 #include "content/browser/tab_contents/tab_contents.h" 14 #include "content/browser/tab_contents/tab_contents.h"
15 15
16 PrintPreviewUI::PrintPreviewUI(TabContents* contents) 16 PrintPreviewUI::PrintPreviewUI(TabContents* contents)
17 : ChromeWebUI(contents), 17 : ChromeWebUI(contents),
18 initial_preview_start_time_(base::TimeTicks::Now()), 18 initial_preview_start_time_(base::TimeTicks::Now()),
19 request_count_(0U) { 19 request_count_(0U),
20 document_cookie_(0) {
20 // WebUI owns |handler_|. 21 // WebUI owns |handler_|.
21 handler_ = new PrintPreviewHandler(); 22 handler_ = new PrintPreviewHandler();
22 AddMessageHandler(handler_->Attach(this)); 23 AddMessageHandler(handler_->Attach(this));
23 24
24 // Set up the chrome://print/ data source. 25 // Set up the chrome://print/ data source.
25 contents->profile()->GetChromeURLDataManager()->AddDataSource( 26 contents->profile()->GetChromeURLDataManager()->AddDataSource(
26 new PrintPreviewDataSource()); 27 new PrintPreviewDataSource());
27 28
28 // Store the PrintPreviewUIAddress as a string. 29 // Store the PrintPreviewUIAddress as a string.
29 // "0x" + deadc0de + '\0' = 2 + 2 * sizeof(this) + 1; 30 // "0x" + deadc0de + '\0' = 2 + 2 * sizeof(this) + 1;
(...skipping 17 matching lines...) Expand all
47 void PrintPreviewUI::OnInitiatorTabClosed( 48 void PrintPreviewUI::OnInitiatorTabClosed(
48 const std::string& initiator_url) { 49 const std::string& initiator_url) {
49 StringValue initiator_tab_url(initiator_url); 50 StringValue initiator_tab_url(initiator_url);
50 CallJavascriptFunction("onInitiatorTabClosed", initiator_tab_url); 51 CallJavascriptFunction("onInitiatorTabClosed", initiator_tab_url);
51 } 52 }
52 53
53 void PrintPreviewUI::OnPrintPreviewRequest() { 54 void PrintPreviewUI::OnPrintPreviewRequest() {
54 request_count_++; 55 request_count_++;
55 } 56 }
56 57
57 void PrintPreviewUI::OnDidGetPreviewPageCount(int page_count) { 58 void PrintPreviewUI::OnDidGetPreviewPageCount(int document_cookie,
59 int page_count) {
58 DCHECK_GT(page_count, 0); 60 DCHECK_GT(page_count, 0);
61 document_cookie_ = document_cookie;
59 FundamentalValue count(page_count); 62 FundamentalValue count(page_count);
60 CallJavascriptFunction("onDidGetPreviewPageCount", count); 63 CallJavascriptFunction("onDidGetPreviewPageCount", count);
61 } 64 }
62 65
63 void PrintPreviewUI::OnDidPreviewPage(int page_number) { 66 void PrintPreviewUI::OnDidPreviewPage(int page_number) {
64 DCHECK_GE(page_number, 0); 67 DCHECK_GE(page_number, 0);
65 FundamentalValue number(page_number); 68 FundamentalValue number(page_number);
66 CallJavascriptFunction("onDidPreviewPage", number); 69 CallJavascriptFunction("onDidPreviewPage", number);
67 } 70 }
68 71
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 112
110 bool PrintPreviewUI::HasPendingRequests() { 113 bool PrintPreviewUI::HasPendingRequests() {
111 return request_count_ > 1; 114 return request_count_ > 1;
112 } 115 }
113 116
114 PrintPreviewDataService* PrintPreviewUI::print_preview_data_service() { 117 PrintPreviewDataService* PrintPreviewUI::print_preview_data_service() {
115 return PrintPreviewDataService::GetInstance(); 118 return PrintPreviewDataService::GetInstance();
116 } 119 }
117 120
118 void PrintPreviewUI::DecrementRequestCount() { 121 void PrintPreviewUI::DecrementRequestCount() {
119 DCHECK_GT(request_count_, 0U);
120 if (request_count_ > 0) 122 if (request_count_ > 0)
121 request_count_--; 123 request_count_--;
122 } 124 }
125
126 int PrintPreviewUI::document_cookie() {
127 return document_cookie_;
128 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/print_preview_ui.h ('k') | chrome/common/print_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698