OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "mash/catalog_viewer/catalog_viewer.h" | 5 #include "mash/catalog_viewer/catalog_viewer.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
43 table_view_parent_(nullptr), | 43 table_view_parent_(nullptr), |
44 observer_(nullptr), | 44 observer_(nullptr), |
45 weak_ptr_factory_(this) { | 45 weak_ptr_factory_(this) { |
46 table_view_ = new views::TableView(this, GetColumns(), views::TEXT_ONLY, | 46 table_view_ = new views::TableView(this, GetColumns(), views::TEXT_ONLY, |
47 false); | 47 false); |
48 set_background(views::Background::CreateStandardPanelBackground()); | 48 set_background(views::Background::CreateStandardPanelBackground()); |
49 | 49 |
50 table_view_parent_ = table_view_->CreateParentIfNecessary(); | 50 table_view_parent_ = table_view_->CreateParentIfNecessary(); |
51 AddChildView(table_view_parent_); | 51 AddChildView(table_view_parent_); |
52 | 52 |
53 catalog_->GetEntries(nullptr, | |
54 base::Bind(&CatalogViewerContents::OnGotCatalogEntries, | |
55 weak_ptr_factory_.GetWeakPtr())); | |
56 // We don't want to show an empty UI so we just block until we have all the | 53 // We don't want to show an empty UI so we just block until we have all the |
57 // data. | 54 // data. GetEntries is a sync call. |
58 catalog_.WaitForIncomingResponse(); | 55 mojo::Array<catalog::mojom::EntryPtr> entries; |
56 catalog_->GetEntries(nullptr, &entries); | |
57 | |
58 OnGotCatalogEntries(entries); | |
sky
2016/07/06 15:47:38
There is no point in OnGotCatalogEntries now. Move
yzshen1
2016/07/06 16:50:26
Not sure whether it matters, but please note that
leonhsl(Using Gerrit)
2016/07/07 07:43:12
Moved OnGotCatalogEntries() impl here.
leonhsl(Using Gerrit)
2016/07/07 07:43:12
Yeah this indeed becomes different with before.. T
| |
59 } | 59 } |
60 ~CatalogViewerContents() override { | 60 ~CatalogViewerContents() override { |
61 table_view_->SetModel(nullptr); | 61 table_view_->SetModel(nullptr); |
62 catalog_viewer_->RemoveWindow(GetWidget()); | 62 catalog_viewer_->RemoveWindow(GetWidget()); |
63 } | 63 } |
64 | 64 |
65 private: | 65 private: |
66 struct Entry { | 66 struct Entry { |
67 Entry(const std::string& name, const std::string& url) | 67 Entry(const std::string& name, const std::string& url) |
68 : name(name), url(url) {} | 68 : name(name), url(url) {} |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 default: | 110 default: |
111 NOTREACHED(); | 111 NOTREACHED(); |
112 break; | 112 break; |
113 } | 113 } |
114 return base::string16(); | 114 return base::string16(); |
115 } | 115 } |
116 void SetObserver(ui::TableModelObserver* observer) override { | 116 void SetObserver(ui::TableModelObserver* observer) override { |
117 observer_ = observer; | 117 observer_ = observer; |
118 } | 118 } |
119 | 119 |
120 void OnGotCatalogEntries(mojo::Array<catalog::mojom::EntryPtr> entries) { | 120 void OnGotCatalogEntries( |
121 const mojo::Array<catalog::mojom::EntryPtr>& entries) { | |
121 entries_.clear(); | 122 entries_.clear(); |
122 for (auto& entry : entries) | 123 for (auto& entry : entries) |
123 entries_.push_back(Entry(entry->display_name, entry->name)); | 124 entries_.push_back(Entry(entry->display_name, entry->name)); |
124 observer_->OnModelChanged(); | 125 observer_->OnModelChanged(); |
125 } | 126 } |
126 | 127 |
127 static std::vector<ui::TableColumn> GetColumns() { | 128 static std::vector<ui::TableColumn> GetColumns() { |
128 std::vector<ui::TableColumn> columns; | 129 std::vector<ui::TableColumn> columns; |
129 | 130 |
130 ui::TableColumn name_column; | 131 ui::TableColumn name_column; |
(...skipping 19 matching lines...) Expand all Loading... | |
150 | 151 |
151 CatalogViewer* catalog_viewer_; | 152 CatalogViewer* catalog_viewer_; |
152 catalog::mojom::CatalogPtr catalog_; | 153 catalog::mojom::CatalogPtr catalog_; |
153 | 154 |
154 views::TableView* table_view_; | 155 views::TableView* table_view_; |
155 views::View* table_view_parent_; | 156 views::View* table_view_parent_; |
156 ui::TableModelObserver* observer_; | 157 ui::TableModelObserver* observer_; |
157 | 158 |
158 std::vector<Entry> entries_; | 159 std::vector<Entry> entries_; |
159 | 160 |
160 base::WeakPtrFactory<CatalogViewerContents> weak_ptr_factory_; | 161 base::WeakPtrFactory<CatalogViewerContents> weak_ptr_factory_; |
sky
2016/07/06 15:47:38
I don't think you'll need this anymore.
leonhsl(Using Gerrit)
2016/07/07 07:43:12
Yeah~ Done and Thanks!
| |
161 | 162 |
162 DISALLOW_COPY_AND_ASSIGN(CatalogViewerContents); | 163 DISALLOW_COPY_AND_ASSIGN(CatalogViewerContents); |
163 }; | 164 }; |
164 | 165 |
165 } // namespace | 166 } // namespace |
166 | 167 |
167 CatalogViewer::CatalogViewer() {} | 168 CatalogViewer::CatalogViewer() {} |
168 CatalogViewer::~CatalogViewer() {} | 169 CatalogViewer::~CatalogViewer() {} |
169 | 170 |
170 void CatalogViewer::RemoveWindow(views::Widget* window) { | 171 void CatalogViewer::RemoveWindow(views::Widget* window) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
208 windows_.push_back(window); | 209 windows_.push_back(window); |
209 } | 210 } |
210 | 211 |
211 void CatalogViewer::Create(shell::Connection* connection, | 212 void CatalogViewer::Create(shell::Connection* connection, |
212 mojom::LaunchableRequest request) { | 213 mojom::LaunchableRequest request) { |
213 bindings_.AddBinding(this, std::move(request)); | 214 bindings_.AddBinding(this, std::move(request)); |
214 } | 215 } |
215 | 216 |
216 } // namespace catalog_viewer | 217 } // namespace catalog_viewer |
217 } // namespace mash | 218 } // namespace mash |
OLD | NEW |