Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / task_manager / printing_information.cc
blobfcc4ca7ca67a98a37c551d63acd4481171f61f0d
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/task_manager/printing_information.h"
7 #include "base/strings/string16.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/favicon/favicon_tab_helper.h"
11 #include "chrome/browser/printing/background_printing_manager.h"
12 #include "chrome/browser/printing/print_preview_dialog_controller.h"
13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/profiles/profile_manager.h"
15 #include "chrome/browser/task_manager/renderer_resource.h"
16 #include "chrome/browser/task_manager/task_manager.h"
17 #include "chrome/browser/task_manager/task_manager_util.h"
18 #include "content/public/browser/render_frame_host.h"
19 #include "content/public/browser/render_process_host.h"
20 #include "content/public/browser/render_view_host.h"
21 #include "content/public/browser/web_contents.h"
22 #include "grit/generated_resources.h"
23 #include "ui/base/l10n/l10n_util.h"
24 #include "ui/base/resource/resource_bundle.h"
25 #include "ui/gfx/image/image_skia.h"
27 using content::WebContents;
29 namespace task_manager {
31 class PrintingResource : public RendererResource {
32 public:
33 explicit PrintingResource(content::WebContents* web_contents);
34 virtual ~PrintingResource();
36 // Resource methods:
37 virtual Type GetType() const OVERRIDE;
38 virtual base::string16 GetTitle() const OVERRIDE;
39 virtual gfx::ImageSkia GetIcon() const OVERRIDE;
40 virtual content::WebContents* GetWebContents() const OVERRIDE;
42 private:
43 content::WebContents* web_contents_;
45 DISALLOW_COPY_AND_ASSIGN(PrintingResource);
48 PrintingResource::PrintingResource(WebContents* web_contents)
49 : RendererResource(web_contents->GetRenderProcessHost()->GetHandle(),
50 web_contents->GetRenderViewHost()),
51 web_contents_(web_contents) {}
53 PrintingResource::~PrintingResource() {}
55 Resource::Type PrintingResource::GetType() const { return RENDERER; }
57 base::string16 PrintingResource::GetTitle() const {
58 return l10n_util::GetStringFUTF16(
59 IDS_TASK_MANAGER_PRINT_PREFIX,
60 util::GetTitleFromWebContents(web_contents_));
63 gfx::ImageSkia PrintingResource::GetIcon() const {
64 FaviconTabHelper::CreateForWebContents(web_contents_);
65 return FaviconTabHelper::FromWebContents(web_contents_)->
66 GetFavicon().AsImageSkia();
69 WebContents* PrintingResource::GetWebContents() const { return web_contents_; }
71 ////////////////////////////////////////////////////////////////////////////////
72 // PrintingInformation class
73 ////////////////////////////////////////////////////////////////////////////////
75 PrintingInformation::PrintingInformation() {}
77 PrintingInformation::~PrintingInformation() {}
79 bool PrintingInformation::CheckOwnership(WebContents* web_contents) {
80 printing::BackgroundPrintingManager* backgrounded_print_jobs =
81 g_browser_process->background_printing_manager();
82 // Is it a background print job?
83 if (backgrounded_print_jobs->HasPrintPreviewDialog(web_contents)) {
84 return true;
86 // Is it a foreground print preview window?
87 if (printing::PrintPreviewDialogController::IsPrintPreviewDialog(
88 web_contents)) {
89 return true;
91 return false;
94 void PrintingInformation::GetAll(const NewWebContentsCallback& callback) {
95 // Add all the pages being background printed.
96 printing::BackgroundPrintingManager* printing_manager =
97 g_browser_process->background_printing_manager();
98 std::set<content::WebContents*> printing_contents =
99 printing_manager->CurrentContentSet();
100 for (std::set<content::WebContents*>::iterator i = printing_contents.begin();
101 i != printing_contents.end();
102 ++i) {
103 callback.Run(*i);
105 // Add all the foreground print preview dialogs.
106 printing::PrintPreviewDialogController::GetInstance()->ForEachPreviewDialog(
107 callback);
110 scoped_ptr<RendererResource> PrintingInformation::MakeResource(
111 WebContents* web_contents) {
112 return scoped_ptr<RendererResource>(new PrintingResource(web_contents));
115 } // namespace task_manager