Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1124)

Unified Diff: chrome/browser/ui/webui/ntp/android/on_context_menu_item_selected_callback.h

Issue 10861042: Add Android's context menu handler used on the NTP. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/ntp/android/on_context_menu_item_selected_callback.h
diff --git a/chrome/browser/ui/webui/ntp/android/on_context_menu_item_selected_callback.h b/chrome/browser/ui/webui/ntp/android/on_context_menu_item_selected_callback.h
new file mode 100644
index 0000000000000000000000000000000000000000..d7b82140027be803f87e06ea24a30fb8882e4660
--- /dev/null
+++ b/chrome/browser/ui/webui/ntp/android/on_context_menu_item_selected_callback.h
@@ -0,0 +1,41 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_UI_WEBUI_NTP_ANDROID_ON_CONTEXT_MENU_ITEM_SELECTED_CALLBACK_H_
+#define CHROME_BROWSER_UI_WEBUI_NTP_ANDROID_ON_CONTEXT_MENU_ITEM_SELECTED_CALLBACK_H_
+
+#include "base/memory/ref_counted.h"
+
+class ContextMenuHandler;
+
+// This class is used by the ContextMenuHandler to create an intermediary object
+// as ContextMenuHandler is not RefCounted and therefore cannot be used in a
+// callback (and we cannot use an Unretained callback as we have no guarantee
+// that the ContextMenuHandler will outlive the callback).
Evan Stade 2012/08/22 00:24:51 any reason not to use a weak pointer?
Ted C 2012/08/22 01:02:38 Hmm...I didn't add this portion initially, so I'm
Evan Stade 2012/08/22 01:12:28 yes, that's what I meant.
Ted C 2012/08/22 20:55:50 Gave it a shot and seems to work just fine.
+class OnContextMenuItemSelectedCallBack
+ : public base::RefCounted<OnContextMenuItemSelectedCallBack> {
+ public:
+ explicit OnContextMenuItemSelectedCallBack(
+ ContextMenuHandler* context_menu_handler);
+
+ // Called by the object responsible for showing the menu when a menu is
+ // selected.
+ void ItemSelected(int item_id);
+
+ // Called by the ContextMenuHandler when its is destroyed so we can clear our
+ // reference to it.
+ void ClearContextMenuHandler();
+
+ private:
+ friend class base::RefCounted<OnContextMenuItemSelectedCallBack>;
+ ~OnContextMenuItemSelectedCallBack();
+
+ // Weak reference; we have a contract with this ContextMenuHandler to call our
+ // ClearContextMenuHander method when it becomes invalid.
+ ContextMenuHandler* context_menu_handler_;
+
+ DISALLOW_COPY_AND_ASSIGN(OnContextMenuItemSelectedCallBack);
+};
+
+#endif // CHROME_BROWSER_UI_WEBUI_NTP_ANDROID_ON_CONTEXT_MENU_ITEM_SELECTED_CALLBACK_H_

Powered by Google App Engine
This is Rietveld 408576698