encoding_menu_controller.h revision 21d179b334e59e9a3bfcaed4c4430bef1bc5759d
1// Copyright (c) 2010 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_TOOLBAR_ENCODING_MENU_CONTROLLER_H_
6#define CHROME_BROWSER_UI_TOOLBAR_ENCODING_MENU_CONTROLLER_H_
7#pragma once
8
9#include <utility>
10#include <string>
11#include <vector>
12
13#include "base/basictypes.h"  // For DISALLOW_COPY_AND_ASSIGN
14#include "base/gtest_prod_util.h"
15#include "base/string16.h"
16
17class Profile;
18
19// Cross-platform logic needed for the encoding menu.
20// For now, we don't need to track state so all methods are static.
21class EncodingMenuController {
22  FRIEND_TEST_ALL_PREFIXES(EncodingMenuControllerTest, EncodingIDsBelongTest);
23  FRIEND_TEST_ALL_PREFIXES(EncodingMenuControllerTest, IsItemChecked);
24
25 public:
26  typedef std::pair<int, string16> EncodingMenuItem;
27  typedef std::vector<EncodingMenuItem> EncodingMenuItemList;
28
29 public:
30  EncodingMenuController() {}
31
32  // Given a command ID, does this command belong to the encoding menu?
33  bool DoesCommandBelongToEncodingMenu(int id);
34
35  // Returns true if the given encoding menu item (specified by item_id)
36  // is checked.  Note that this header is included from objc, where the name
37  // "id" is reserved.
38  bool IsItemChecked(Profile* browser_profile,
39                     const std::string& current_tab_encoding,
40                     int item_id);
41
42  // Fills in a list of menu items in the order they should appear in the menu.
43  // Items whose ids are 0 are separators.
44  void GetEncodingMenuItems(Profile* profile,
45                            EncodingMenuItemList* menuItems);
46
47 private:
48  // List of all valid encoding GUI IDs.
49  static const int kValidEncodingIds[];
50  const int* ValidGUIEncodingIDs();
51  int NumValidGUIEncodingIDs();
52
53  DISALLOW_COPY_AND_ASSIGN(EncodingMenuController);
54};
55
56#endif  // CHROME_BROWSER_UI_TOOLBAR_ENCODING_MENU_CONTROLLER_H_
57