Fixed crash if tab closes while WebShare picker dialog is open.
Now, in this case, the picker dialog will do nothing (it has a weak
pointer to the share service which is invalidated if the tab closes).
Significantly reworked unit test to make testing this case possible:
instead of synchronously closing the picker in ShowPickerDialog, it now
stores the callback and exits the run-loop, allowing the individual
tests to call the callback as they wish. The new test
ShareServiceDeletion deletes the share service before calling the
callback, which would have crashed before this fix.
BUG=690775
Review-Url: https://codereview.chromium.org/2688413006
Cr-Commit-Position: refs/heads/master@{#451169}
diff --git a/chrome/browser/webshare/share_service_impl.h b/chrome/browser/webshare/share_service_impl.h
index ed1cde81..7fb160931 100644
--- a/chrome/browser/webshare/share_service_impl.h
+++ b/chrome/browser/webshare/share_service_impl.h
@@ -10,6 +10,7 @@
#include <vector>
#include "base/gtest_prod_util.h"
+#include "base/memory/weak_ptr.h"
#include "base/strings/string16.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_dialogs.h"
@@ -89,6 +90,8 @@
const ShareCallback& callback,
base::Optional<std::string> result);
+ base::WeakPtrFactory<ShareServiceImpl> weak_factory_;
+
DISALLOW_COPY_AND_ASSIGN(ShareServiceImpl);
};