summaryrefslogtreecommitdiffstats
path: root/rlz
diff options
context:
space:
mode:
authorthakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-21 22:53:54 +0000
committerthakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-21 22:53:54 +0000
commit27e908b301f1fe34aa479a6b14c46379841f3029 (patch)
tree495125bded5b217fe76a295170d228a2e34c12c2 /rlz
parentee914f9b498d65dde5f798ad10d422ab0dd3fc76 (diff)
downloadchromium_src-27e908b301f1fe34aa479a6b14c46379841f3029.zip
chromium_src-27e908b301f1fe34aa479a6b14c46379841f3029.tar.gz
chromium_src-27e908b301f1fe34aa479a6b14c46379841f3029.tar.bz2
mac/rlz: Remove an incorrect check
As a comment in the ScopedRlzValueStoreLock destructor explains: // Check that "store_ set" => "file_lock acquired". The converse isn't true, // for example if the rlz data file can't be read. So don't CHECK when that happens, instead treat it like lock acquisition failures: Silently drop events when that happens. I added a unit test for this scenario. Also pass O_RDWR to open(), as posix requires one of O_READ, O_WRITE, or O_RDWR. BUG=143950 Review URL: https://chromiumcodereview.appspot.com/10828424 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152659 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'rlz')
-rw-r--r--rlz/lib/rlz_lib_test.cc19
-rw-r--r--rlz/lib/rlz_value_store.h3
-rw-r--r--rlz/mac/lib/rlz_value_store_mac.mm18
3 files changed, 35 insertions, 5 deletions
diff --git a/rlz/lib/rlz_lib_test.cc b/rlz/lib/rlz_lib_test.cc
index 118f48c..2ab1bb3 100644
--- a/rlz/lib/rlz_lib_test.cc
+++ b/rlz/lib/rlz_lib_test.cc
@@ -20,6 +20,7 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "rlz/lib/rlz_lib.h"
+#include "rlz/lib/rlz_value_store.h"
#include "rlz/test/rlz_test_helpers.h"
#if defined(OS_WIN)
@@ -871,4 +872,22 @@ TEST_F(RlzLibTest, ConcurrentStoreAccessWithProcessExitsWhileLockHeld) {
EXPECT_TRUE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER,
rlz_lib::IE_DEFAULT_SEARCH, rlz_lib::INSTALL));
}
+
+TEST_F(RlzLibTest, LockAcquistionSucceedsButPlistCannotBeCreated) {
+ // See the comment at the top of WriteFails.
+ if (!rlz_lib::SupplementaryBranding::GetBrand().empty())
+ return;
+
+ // Create a directory where the rlz file is supposed to appear. This way,
+ // the lock file can be created successfully, but creation of the rlz file
+ // itself will fail.
+ int mkdir_result = mkdir(rlz_lib::testing::RlzPlistFilenameStr().c_str(),
+ 0500);
+ ASSERT_EQ(0, mkdir_result);
+
+ rlz_lib::SupplementaryBranding branding("TEST");
+ EXPECT_FALSE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER,
+ rlz_lib::IE_DEFAULT_SEARCH, rlz_lib::INSTALL));
+}
+
#endif
diff --git a/rlz/lib/rlz_value_store.h b/rlz/lib/rlz_value_store.h
index d41421b..f45ac25 100644
--- a/rlz/lib/rlz_value_store.h
+++ b/rlz/lib/rlz_value_store.h
@@ -107,6 +107,9 @@ class ScopedRlzValueStoreLock {
namespace testing {
// Prefix |directory| to the path where the RLZ data file lives, for tests.
void SetRlzStoreDirectory(const FilePath& directory);
+
+// Returns the path of the plist file used as data store.
+std::string RlzPlistFilenameStr();
} // namespace testing
#endif // defined(OS_MACOSX)
diff --git a/rlz/mac/lib/rlz_value_store_mac.mm b/rlz/mac/lib/rlz_value_store_mac.mm
index b1d082d..795a0cc 100644
--- a/rlz/mac/lib/rlz_value_store_mac.mm
+++ b/rlz/mac/lib/rlz_value_store_mac.mm
@@ -270,7 +270,9 @@ bool RecursiveCrossProcessLock::TryGetCrossProcessLock(
const int kSleepPerTryMS = 200;
CHECK(file_lock_ == -1);
- file_lock_ = open([lock_filename fileSystemRepresentation], O_CREAT, 0666);
+ file_lock_ = open([lock_filename fileSystemRepresentation],
+ O_RDWR | O_CREAT,
+ 0666);
if (file_lock_ == -1)
return false;
@@ -354,8 +356,8 @@ NSString* RlzPlistFilename() {
// Returns the path of the rlz lock file, also creates the parent directory
// path if it doesn't exist.
NSString* RlzLockFilename() {
- NSString* const kRlzFile = @"flockfile";
- return [CreateRlzDirectory() stringByAppendingPathComponent:kRlzFile];
+ NSString* const kRlzLockfile = @"flockfile";
+ return [CreateRlzDirectory() stringByAppendingPathComponent:kRlzLockfile];
}
} // namespace
@@ -377,8 +379,8 @@ ScopedRlzValueStoreLock::ScopedRlzValueStoreLock() {
}
if (g_lock_depth > 1) {
- // Reuse the already existing store object.
- CHECK(g_store_object);
+ // Reuse the already existing store object. Note that it can be NULL when
+ // lock acquisition succeeded but the rlz data file couldn't be read.
store_.reset(g_store_object);
return;
}
@@ -449,6 +451,12 @@ void SetRlzStoreDirectory(const FilePath& directory) {
}
}
+std::string RlzPlistFilenameStr() {
+ @autoreleasepool {
+ return std::string([RlzPlistFilename() fileSystemRepresentation]);
+ }
+}
+
} // namespace testing
} // namespace rlz_lib