Commit d4cb64a0 authored by vitalybuka's avatar vitalybuka Committed by Commit bot

Removed redundant PrintingUIWebContentsObserver.

BUG=374321

Review URL: https://codereview.chromium.org/506273004

Cr-Commit-Position: refs/heads/master@{#292022}
parent 622b0d07
......@@ -13,7 +13,6 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/printing/print_job.h"
#include "chrome/browser/printing/printing_ui_web_contents_observer.h"
#include "chrome/grit/generated_resources.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_service.h"
......@@ -46,58 +45,33 @@ class PrintingContextDelegate : public PrintingContext::Delegate {
virtual std::string GetAppLocale() OVERRIDE;
private:
void InitOnUiThread(int render_process_id, int render_view_id);
scoped_ptr<PrintingUIWebContentsObserver> web_contents_observer_;
base::WeakPtrFactory<PrintingContextDelegate> weak_ptr_factory_;
int render_process_id_;
int render_view_id_;
};
PrintingContextDelegate::PrintingContextDelegate(int render_process_id,
int render_view_id)
: weak_ptr_factory_(this) {
InitOnUiThread(render_process_id, render_view_id);
: render_process_id_(render_process_id),
render_view_id_(render_view_id) {
}
PrintingContextDelegate::~PrintingContextDelegate() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
}
gfx::NativeView PrintingContextDelegate::GetParentView() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (!web_contents_observer_)
content::RenderViewHost* view =
content::RenderViewHost::FromID(render_process_id_, render_view_id_);
if (!view)
return NULL;
return web_contents_observer_->GetParentView();
content::WebContents* wc = content::WebContents::FromRenderViewHost(view);
return wc ? wc->GetNativeView() : NULL;
}
std::string PrintingContextDelegate::GetAppLocale() {
return g_browser_process->GetApplicationLocale();
}
void PrintingContextDelegate::InitOnUiThread(int render_process_id,
int render_view_id) {
if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
// All data initialized here should be accessed on UI thread. Because object
// is being constructed now, anything that is going to access
// PrintingContextDelegate on UI thread would be scheduled after the tasks
// below.
BrowserThread::PostTask(BrowserThread::UI,
FROM_HERE,
base::Bind(&PrintingContextDelegate::InitOnUiThread,
weak_ptr_factory_.GetWeakPtr(),
render_process_id,
render_view_id));
return;
}
content::RenderViewHost* view =
content::RenderViewHost::FromID(render_process_id, render_view_id);
if (!view)
return;
content::WebContents* wc = content::WebContents::FromRenderViewHost(view);
if (!wc)
return;
web_contents_observer_.reset(new PrintingUIWebContentsObserver(wc));
}
void NotificationCallback(PrintJobWorkerOwner* print_job,
JobEventDetails::Type detail_type,
PrintedDocument* document,
......
......@@ -132,9 +132,7 @@ class PrintJobWorker {
void UseDefaultSettings();
// Printing context delegate.
scoped_ptr<PrintingContext::Delegate,
content::BrowserThread::DeleteOnUIThread>
printing_context_delegate_;
scoped_ptr<PrintingContext::Delegate> printing_context_delegate_;
// Information about the printer setting.
scoped_ptr<PrintingContext> printing_context_;
......
......@@ -10,7 +10,6 @@
#include "base/threading/thread_restrictions.h"
#include "base/values.h"
#include "chrome/browser/printing/print_job_worker.h"
#include "chrome/browser/printing/printing_ui_web_contents_observer.h"
namespace printing {
......
......@@ -10,7 +10,6 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/printing/print_job_manager.h"
#include "chrome/browser/printing/printer_query.h"
#include "chrome/browser/printing/printing_ui_web_contents_observer.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_io_data.h"
#include "chrome/common/print_messages.h"
......
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/printing/printing_ui_web_contents_observer.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/web_contents.h"
namespace printing {
PrintingUIWebContentsObserver::PrintingUIWebContentsObserver(
content::WebContents* web_contents)
: content::WebContentsObserver(web_contents) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
}
PrintingUIWebContentsObserver::~PrintingUIWebContentsObserver() {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
}
gfx::NativeView PrintingUIWebContentsObserver::GetParentView() {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
return web_contents() ? web_contents()->GetNativeView() : NULL;
}
} // namespace printing
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_PRINTING_PRINTING_UI_WEB_CONTENTS_OBSERVER_H_
#define CHROME_BROWSER_PRINTING_PRINTING_UI_WEB_CONTENTS_OBSERVER_H_
#include "base/basictypes.h"
#include "content/public/browser/web_contents_observer.h"
#include "ui/gfx/native_widget_types.h"
namespace printing {
// Wrapper used to keep track of the lifetime of a WebContents.
// Lives on the UI thread.
class PrintingUIWebContentsObserver : public content::WebContentsObserver {
public:
explicit PrintingUIWebContentsObserver(content::WebContents* web_contents);
virtual ~PrintingUIWebContentsObserver();
// Return the parent NativeView of the observed WebContents.
gfx::NativeView GetParentView();
private:
DISALLOW_COPY_AND_ASSIGN(PrintingUIWebContentsObserver);
};
} // namespace printing
#endif // CHROME_BROWSER_PRINTING_PRINTING_UI_WEB_CONTENTS_OBSERVER_H_
......@@ -1874,8 +1874,6 @@
'browser/printing/printer_query.h',
'browser/printing/printing_message_filter.cc',
'browser/printing/printing_message_filter.h',
'browser/printing/printing_ui_web_contents_observer.cc',
'browser/printing/printing_ui_web_contents_observer.h',
],
# Used on top of the "basic" sources when enable_printing == 1 (full).
'chrome_browser_full_printing_sources': [
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment