[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / ui / views / create_application_shortcut_view.h
blob7a503258ad6246841876ac43b54e5099c6d2f2f9
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_VIEWS_CREATE_APPLICATION_SHORTCUT_VIEW_H_
6 #define CHROME_BROWSER_UI_VIEWS_CREATE_APPLICATION_SHORTCUT_VIEW_H_
8 #include <string>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "chrome/browser/web_applications/web_app.h"
14 #include "ui/views/controls/button/button.h"
15 #include "ui/views/window/dialog_delegate.h"
17 class FaviconDownloadHelper;
18 class GURL;
19 class Profile;
20 class SkBitmap;
22 namespace content {
23 class WebContents;
26 namespace extensions {
27 class Extension;
30 namespace views {
31 class Checkbox;
32 class Label;
35 // CreateShortcutViewCommon implements a dialog that asks user where to create
36 // the shortcut for given web app. There are two variants of this dialog:
37 // Shortcuts that load a URL in an app-like window, and shortcuts that load
38 // a chrome app (the kind you see under "apps" on the new tabs page) in an app
39 // window. These are implemented as subclasses of CreateShortcutViewCommon.
40 class CreateApplicationShortcutView : public views::DialogDelegateView,
41 public views::ButtonListener {
42 public:
43 explicit CreateApplicationShortcutView(Profile* profile);
44 virtual ~CreateApplicationShortcutView();
46 // Initialize the controls on the dialog.
47 void InitControls();
49 // Overridden from views::View:
50 virtual gfx::Size GetPreferredSize() const OVERRIDE;
52 // Overridden from views::DialogDelegate:
53 virtual base::string16 GetDialogButtonLabel(
54 ui::DialogButton button) const OVERRIDE;
55 virtual bool IsDialogButtonEnabled(ui::DialogButton button) const OVERRIDE;
56 virtual ui::ModalType GetModalType() const OVERRIDE;
57 virtual base::string16 GetWindowTitle() const OVERRIDE;
58 virtual bool Accept() OVERRIDE;
60 // Overridden from views::ButtonListener:
61 virtual void ButtonPressed(views::Button* sender,
62 const ui::Event& event) OVERRIDE;
64 protected:
65 // Adds a new check-box as a child to the view.
66 views::Checkbox* AddCheckbox(const base::string16& text, bool checked);
68 // Profile in which the shortcuts will be created.
69 Profile* profile_;
71 // UI elements on the dialog.
72 views::View* app_info_;
73 views::Label* create_shortcuts_label_;
74 views::Checkbox* desktop_check_box_;
75 views::Checkbox* menu_check_box_;
76 views::Checkbox* quick_launch_check_box_;
78 // Target shortcut info.
79 web_app::ShortcutInfo shortcut_info_;
80 // If false, the shortcut will be created in the root level of the Start Menu.
81 bool create_in_chrome_apps_subdir_;
83 DISALLOW_COPY_AND_ASSIGN(CreateApplicationShortcutView);
86 // Create an application shortcut pointing to a URL.
87 class CreateUrlApplicationShortcutView : public CreateApplicationShortcutView {
88 public:
89 explicit CreateUrlApplicationShortcutView(content::WebContents* web_contents);
90 virtual ~CreateUrlApplicationShortcutView();
92 virtual bool Accept() OVERRIDE;
94 private:
95 // Fetch the largest unprocessed icon.
96 // The first largest icon downloaded and decoded successfully will be used.
97 void FetchIcon();
99 // Favicon download callback.
100 void DidDownloadFavicon(
101 int requested_size,
102 int id,
103 int http_status_code,
104 const GURL& image_url,
105 const std::vector<SkBitmap>& bitmaps,
106 const std::vector<gfx::Size>& original_bitmap_sizes);
108 // The tab whose URL is being turned into an app.
109 content::WebContents* web_contents_;
111 // Pending app icon download tracked by us.
112 int pending_download_id_;
114 // Unprocessed icons from the WebApplicationInfo passed in.
115 web_app::IconInfoList unprocessed_icons_;
117 base::WeakPtrFactory<CreateUrlApplicationShortcutView> weak_ptr_factory_;
119 DISALLOW_COPY_AND_ASSIGN(CreateUrlApplicationShortcutView);
122 // Create an application shortcut pointing to a chrome application.
123 class CreateChromeApplicationShortcutView
124 : public CreateApplicationShortcutView {
125 public:
126 CreateChromeApplicationShortcutView(
127 Profile* profile,
128 const extensions::Extension* app,
129 const base::Callback<void(bool)>& close_callback);
130 virtual ~CreateChromeApplicationShortcutView();
131 virtual bool Accept() OVERRIDE;
132 virtual bool Cancel() OVERRIDE;
134 private:
135 void OnShortcutInfoLoaded(
136 const web_app::ShortcutInfo& shortcut_info);
138 base::Callback<void(bool)> close_callback_;
140 base::WeakPtrFactory<CreateChromeApplicationShortcutView> weak_ptr_factory_;
142 DISALLOW_COPY_AND_ASSIGN(CreateChromeApplicationShortcutView);
145 #endif // CHROME_BROWSER_UI_VIEWS_CREATE_APPLICATION_SHORTCUT_VIEW_H_