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

Side by Side Diff: chrome/browser/printing/print_job_worker.cc

Issue 506273004: Removed redundant PrintingUIWebContentsObserver. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tue Aug 26 14:12:01 PDT 2014 Created 6 years, 3 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 | « chrome/browser/printing/print_job_worker.h ('k') | chrome/browser/printing/printer_query.cc » ('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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/printing/print_job_worker.h" 5 #include "chrome/browser/printing/print_job_worker.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/chrome_notification_types.h" 14 #include "chrome/browser/chrome_notification_types.h"
15 #include "chrome/browser/printing/print_job.h" 15 #include "chrome/browser/printing/print_job.h"
16 #include "chrome/browser/printing/printing_ui_web_contents_observer.h"
17 #include "chrome/grit/generated_resources.h" 16 #include "chrome/grit/generated_resources.h"
18 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
19 #include "content/public/browser/notification_service.h" 18 #include "content/public/browser/notification_service.h"
20 #include "content/public/browser/render_view_host.h" 19 #include "content/public/browser/render_view_host.h"
21 #include "content/public/browser/web_contents.h" 20 #include "content/public/browser/web_contents.h"
22 #include "printing/print_job_constants.h" 21 #include "printing/print_job_constants.h"
23 #include "printing/printed_document.h" 22 #include "printing/printed_document.h"
24 #include "printing/printed_page.h" 23 #include "printing/printed_page.h"
25 #include "printing/printing_utils.h" 24 #include "printing/printing_utils.h"
26 #include "ui/base/l10n/l10n_util.h" 25 #include "ui/base/l10n/l10n_util.h"
(...skipping 12 matching lines...) Expand all
39 38
40 class PrintingContextDelegate : public PrintingContext::Delegate { 39 class PrintingContextDelegate : public PrintingContext::Delegate {
41 public: 40 public:
42 PrintingContextDelegate(int render_process_id, int render_view_id); 41 PrintingContextDelegate(int render_process_id, int render_view_id);
43 virtual ~PrintingContextDelegate(); 42 virtual ~PrintingContextDelegate();
44 43
45 virtual gfx::NativeView GetParentView() OVERRIDE; 44 virtual gfx::NativeView GetParentView() OVERRIDE;
46 virtual std::string GetAppLocale() OVERRIDE; 45 virtual std::string GetAppLocale() OVERRIDE;
47 46
48 private: 47 private:
49 void InitOnUiThread(int render_process_id, int render_view_id); 48 int render_process_id_;
50 49 int render_view_id_;
51 scoped_ptr<PrintingUIWebContentsObserver> web_contents_observer_;
52 base::WeakPtrFactory<PrintingContextDelegate> weak_ptr_factory_;
53 }; 50 };
54 51
55 PrintingContextDelegate::PrintingContextDelegate(int render_process_id, 52 PrintingContextDelegate::PrintingContextDelegate(int render_process_id,
56 int render_view_id) 53 int render_view_id)
57 : weak_ptr_factory_(this) { 54 : render_process_id_(render_process_id),
58 InitOnUiThread(render_process_id, render_view_id); 55 render_view_id_(render_view_id) {
59 } 56 }
60 57
61 PrintingContextDelegate::~PrintingContextDelegate() { 58 PrintingContextDelegate::~PrintingContextDelegate() {
62 DCHECK_CURRENTLY_ON(BrowserThread::UI);
63 } 59 }
64 60
65 gfx::NativeView PrintingContextDelegate::GetParentView() { 61 gfx::NativeView PrintingContextDelegate::GetParentView() {
66 DCHECK_CURRENTLY_ON(BrowserThread::UI); 62 DCHECK_CURRENTLY_ON(BrowserThread::UI);
67 if (!web_contents_observer_) 63 content::RenderViewHost* view =
64 content::RenderViewHost::FromID(render_process_id_, render_view_id_);
65 if (!view)
68 return NULL; 66 return NULL;
69 return web_contents_observer_->GetParentView(); 67 content::WebContents* wc = content::WebContents::FromRenderViewHost(view);
68 return wc ? wc->GetNativeView() : NULL;
70 } 69 }
71 70
72 std::string PrintingContextDelegate::GetAppLocale() { 71 std::string PrintingContextDelegate::GetAppLocale() {
73 return g_browser_process->GetApplicationLocale(); 72 return g_browser_process->GetApplicationLocale();
74 } 73 }
75 74
76 void PrintingContextDelegate::InitOnUiThread(int render_process_id,
77 int render_view_id) {
78 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
79 // All data initialized here should be accessed on UI thread. Because object
80 // is being constructed now, anything that is going to access
81 // PrintingContextDelegate on UI thread would be scheduled after the tasks
82 // below.
83 BrowserThread::PostTask(BrowserThread::UI,
84 FROM_HERE,
85 base::Bind(&PrintingContextDelegate::InitOnUiThread,
86 weak_ptr_factory_.GetWeakPtr(),
87 render_process_id,
88 render_view_id));
89 return;
90 }
91 content::RenderViewHost* view =
92 content::RenderViewHost::FromID(render_process_id, render_view_id);
93 if (!view)
94 return;
95 content::WebContents* wc = content::WebContents::FromRenderViewHost(view);
96 if (!wc)
97 return;
98 web_contents_observer_.reset(new PrintingUIWebContentsObserver(wc));
99 }
100
101 void NotificationCallback(PrintJobWorkerOwner* print_job, 75 void NotificationCallback(PrintJobWorkerOwner* print_job,
102 JobEventDetails::Type detail_type, 76 JobEventDetails::Type detail_type,
103 PrintedDocument* document, 77 PrintedDocument* document,
104 PrintedPage* page) { 78 PrintedPage* page) {
105 JobEventDetails* details = new JobEventDetails(detail_type, document, page); 79 JobEventDetails* details = new JobEventDetails(detail_type, document, page);
106 content::NotificationService::current()->Notify( 80 content::NotificationService::current()->Notify(
107 chrome::NOTIFICATION_PRINT_JOB_EVENT, 81 chrome::NOTIFICATION_PRINT_JOB_EVENT,
108 // We know that is is a PrintJob object in this circumstance. 82 // We know that is is a PrintJob object in this circumstance.
109 content::Source<PrintJob>(static_cast<PrintJob*>(print_job)), 83 content::Source<PrintJob>(static_cast<PrintJob*>(print_job)),
110 content::Details<JobEventDetails>(details)); 84 content::Details<JobEventDetails>(details));
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 document_, 422 document_,
449 scoped_refptr<PrintedPage>())); 423 scoped_refptr<PrintedPage>()));
450 Cancel(); 424 Cancel();
451 425
452 // Makes sure the variables are reinitialized. 426 // Makes sure the variables are reinitialized.
453 document_ = NULL; 427 document_ = NULL;
454 page_number_ = PageNumber::npos(); 428 page_number_ = PageNumber::npos();
455 } 429 }
456 430
457 } // namespace printing 431 } // namespace printing
OLDNEW
« no previous file with comments | « chrome/browser/printing/print_job_worker.h ('k') | chrome/browser/printing/printer_query.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698