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