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_WEBUI_OPTIONS_COOKIES_VIEW_HANDLER_H_
6#define CHROME_BROWSER_UI_WEBUI_OPTIONS_COOKIES_VIEW_HANDLER_H_
7
8#include "base/compiler_specific.h"
9#include "base/memory/scoped_ptr.h"
10#include "chrome/browser/browsing_data/cookies_tree_model.h"
11#include "chrome/browser/ui/webui/options/options_ui.h"
12
13class CookiesTreeModelUtil;
14
15namespace options {
16
17class CookiesViewHandler : public OptionsPageUIHandler,
18                           public CookiesTreeModel::Observer {
19 public:
20  CookiesViewHandler();
21  virtual ~CookiesViewHandler();
22
23  // OptionsPageUIHandler implementation.
24  virtual void GetLocalizedValues(
25      base::DictionaryValue* localized_strings) OVERRIDE;
26  virtual void RegisterMessages() OVERRIDE;
27
28  // CookiesTreeModel::Observer implementation.
29  virtual void TreeNodesAdded(ui::TreeModel* model,
30                              ui::TreeModelNode* parent,
31                              int start,
32                              int count) OVERRIDE;
33  virtual void TreeNodesRemoved(ui::TreeModel* model,
34                                ui::TreeModelNode* parent,
35                                int start,
36                                int count) OVERRIDE;
37  virtual void TreeNodeChanged(ui::TreeModel* model,
38                               ui::TreeModelNode* node) OVERRIDE {}
39  virtual void TreeModelBeginBatch(CookiesTreeModel* model) OVERRIDE;
40  virtual void TreeModelEndBatch(CookiesTreeModel* model) OVERRIDE;
41
42 private:
43  // Creates the CookiesTreeModel if neccessary.
44  void EnsureCookiesTreeModelCreated();
45
46  // Updates search filter for cookies tree model.
47  void UpdateSearchResults(const base::ListValue* args);
48
49  // Remove all sites data.
50  void RemoveAll(const base::ListValue* args);
51
52  // Remove selected sites data.
53  void Remove(const base::ListValue* args);
54
55  // Get the tree node using the tree path info in |args| and call
56  // SendChildren to pass back children nodes data to WebUI.
57  void LoadChildren(const base::ListValue* args);
58
59  // Get children nodes data and pass it to 'CookiesView.loadChildren' to
60  // update the WebUI.
61  void SendChildren(const CookieTreeNode* parent);
62
63  // Reloads the CookiesTreeModel and passes the nodes to
64  // 'CookiesView.loadChildren' to update the WebUI.
65  void ReloadCookies(const base::ListValue* args);
66
67  // The Cookies Tree model
68  scoped_ptr<CookiesTreeModel> cookies_tree_model_;
69
70  // Flag to indicate whether there is a batch update in progress.
71  bool batch_update_;
72
73  scoped_ptr<CookiesTreeModelUtil> model_util_;
74
75  DISALLOW_COPY_AND_ASSIGN(CookiesViewHandler);
76};
77
78}  // namespace options
79
80#endif  // CHROME_BROWSER_UI_WEBUI_OPTIONS_COOKIES_VIEW_HANDLER_H_
81