status_tray_win.h revision 5c02ac1a9c1b504631c0a3d2b6e737b5d738bae1
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.
4
5#ifndef CHROME_BROWSER_UI_VIEWS_STATUS_ICONS_STATUS_TRAY_WIN_H_
6#define CHROME_BROWSER_UI_VIEWS_STATUS_ICONS_STATUS_TRAY_WIN_H_
7
8#include <windows.h>
9
10#include "base/compiler_specific.h"
11#include "base/memory/scoped_ptr.h"
12#include "chrome/browser/status_icons/status_tray.h"
13
14class StatusIconWin;
15
16// A class that's responsible for increasing, if possible, the visibility
17// of a status tray icon on the taskbar. The default implementation sends
18// a task to a worker thread each time EnqueueChange is called.
19class StatusTrayStateChangerProxy {
20 public:
21  // Called by StatusTrayWin to request upgraded visibility on the icon
22  // represented by the |icon_id|, |window| pair.
23  virtual void EnqueueChange(UINT icon_id, HWND window) = 0;
24};
25
26class StatusTrayWin : public StatusTray {
27 public:
28  StatusTrayWin();
29  ~StatusTrayWin();
30
31  void UpdateIconVisibilityInBackground(StatusIconWin* status_icon);
32
33  // Exposed for testing.
34  LRESULT CALLBACK
35      WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);
36
37 protected:
38  // Overriden from StatusTray:
39  virtual StatusIcon* CreatePlatformStatusIcon(StatusIconType type,
40                                               const gfx::ImageSkia& image,
41                                               const base::string16& tool_tip)
42      OVERRIDE;
43
44 private:
45  FRIEND_TEST_ALL_PREFIXES(StatusTrayWinTest, EnsureVisibleTest);
46
47  // Static callback invoked when a message comes in to our messaging window.
48  static LRESULT CALLBACK
49      WndProcStatic(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);
50
51  UINT NextIconId();
52
53  void SetStatusTrayStateChangerProxyForTest(
54      scoped_ptr<StatusTrayStateChangerProxy> proxy);
55
56  // The unique icon ID we will assign to the next icon.
57  UINT next_icon_id_;
58
59  // The window class of |window_|.
60  ATOM atom_;
61
62  // The handle of the module that contains the window procedure of |window_|.
63  HMODULE instance_;
64
65  // The window used for processing events.
66  HWND window_;
67
68  // The message ID of the "TaskbarCreated" message, sent to us when we need to
69  // reset our status icons.
70  UINT taskbar_created_message_;
71
72  // Manages changes performed on a background thread to manipulate visibility
73  // of notification icons.
74  scoped_ptr<StatusTrayStateChangerProxy> state_changer_proxy_;
75
76  DISALLOW_COPY_AND_ASSIGN(StatusTrayWin);
77};
78
79#endif  // CHROME_BROWSER_UI_VIEWS_STATUS_ICONS_STATUS_TRAY_WIN_H_
80
81